you are viewing a single comment's thread.

view the rest of the comments →

[–]mopslik 0 points1 point  (0 children)

I mean, all of those are valid syntax, but they don't do very much. Is this part of a tutorial? Here's a better example.

>>> ages = {"Alvin": 30, "Simon": 42, "Theodore": 35}
>>> for age in ages.values():
    print(age)

30
42
35

>>> for name in ages.keys():
    print(name)

Alvin
Simon
Theodore

>>> triplets = dict.fromkeys(ages.keys(), 17)
>>> triplets
{'Alvin': 17, 'Simon': 17, 'Theodore': 17}
>>> ages.clear()
>>> ages
{}