Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Loop using items

  • items
people = {
    "Tal"  : "123",
    "Maya" : "456",
    "Ruth" : "789",
}

for name, uid in people.items():
    print(f"{name} => {uid}")
Tal => 123
Maya => 456
Ruth => 789
user = {
    'fname': 'Foo',
    'lname': 'Bar',
}

for tpl in user.items():      # iterates on tuples
    print(f"{tpl[0]} -> {tpl[1]}")
    print("{} -> {}".format(*tpl))

# fname -> Foo
# fname -> Foo
# lname -> Bar
# lname -> Bar