Collections — Lists & Dicts
Larz covers how Larzscript stores many values at once: lists for ordered values, dicts for looking values up by key, and the same len() and for that work on both.
lists
Values in brackets, in order. Index from zero, and push() adds one more to the end:
let fruits = ["apple", "banana", "cherry"]
print(fruits[0])
push(fruits, "date")
print(fruits)
print(len(fruits))
for f in fruits {
print(f)
}Output
apple [apple, banana, cherry, date] 4 apple banana cherry date
dicts
Keys paired with values, in braces. Look up or set a value with the key in brackets, same as a list:
let prices = {"apple": 2, "banana": 1, "cherry": 5}
print(prices["apple"])
prices["date"] = 3
print(len(prices))
for k in prices {
print(k, prices[k])
}Output
2 4 apple 2 banana 1 cherry 5 date 3
Every snippet on this page is run through the real larzscript interpreter, not hand-typed — what you see in the Output blocks is the actual output, for everything shown: list indexing and push, dict lookup and assignment, and for walking both.
Related
Lesson 6: Strings & Text Processingupper/lower, slicing, strip, split and join - what's next after lists and dicts.→Lesson 4: Functions & Recursionfn, return, and recursion - the push() and len() calls in this lesson are just functions like the ones you wrote there.→Lesson 3: Control Flowif/else, unless, while, and for - the for loop this lesson walks lists and dicts with.→What Is Larzscript?The full explainer on the money-native pitch, for more depth than a lesson video covers.→Learn Larzscript Cookbook29 short "how to X in Larzscript" recipes, many returning dicts exactly like the ones built here.→