Language Reference
Collections
Work with lists and dictionaries using clear, readable statements.
Collection patterns
- Initialize lists and dictionaries inline.
- Use readable list comprehensions.
- Access items with brackets.
Lists and dictionaries
Create collections in a single line, then access items with standard Python notation.
collections.pln
create a list named users with ["Ada", "Lin", "Sam"]
create a dictionary named profile with {"name": "Ada", "role": "admin"}
print profile["role"]
Updating collections
Append to lists and update dictionary keys with readable assignments.
updates.pln
create a list named users with ["Ada", "Lin"]
create a dictionary named profile with {"name": "Ada", "role": "engineer"}
set users to users + ["Sam"]
set profile["team"] to "platform"
print users[0]
print profile["team"]
Membership and size
Use in and len() to check membership and size.
membership.pln
create a list named users with ["Ada", "Lin", "Sam"]
if "Ada" in users then print "User exists"
set total to len(users)
print "User count: " + str(total)
Nested collections
Store structured records as dictionaries inside lists.
nested.pln
create a list named users with [
{"name": "Ada", "active": true},
{"name": "Lin", "active": false}
]
print users[0]["name"]
Readable list building
Use natural language filters to build new lists from existing data.
list_build.pln
create a list of user["name"] for each user in users if user["active"] is true
Python collection helpers
Valid Python lines pass through, so list and dictionary methods are available when needed.
interop_collections.pln
users = ["Ada", "Lin"]
users.append("Sam")
last_user = users.pop()
profile = {"name": "Ada"}
role = profile.get("role", "guest")
print last_user
print role
Organization tips
- Prefer dictionaries for labeled data and lists for sequences.
- Keep collection names plural to clarify intent.
- Use list creation lines to keep transformations readable.