Larzscript Course · Lesson 5 of 15

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.

← Lesson 4Course syllabusGitHub