I’m creating a dictionary filled with people’s name and birthdate- is it possible to iterate through it, looking at each item’s value? Or should I use a list? I can’t seem to find any methods for iteration.
Yes it’s possible using the dictionary’s keys()
method.
You really should take a look at Starlark’s documentation as it has the answers to most of these things:
Example:
# supposing your dictionary looks like this
birthdays = {
"John": "05/01/1980",
"Jack": "04/03/1991"
}
for name in birthdays.keys():
birth_date = birthdays[name]
print(name + "'s birthday is at " + birth_date)
# will print two lines:
# John's birthday is at 05/01/1980
# Jack's birthday is at 04/03/1991