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 over dictionary keys

Looping over the "dictionary" is just like looping over the keys, but personally I prefer when we use the somedictionary.keys() expression.

user = {
    'fname': 'Foo',
    'lname': 'Bar',
}

for key in user:
    print(f"{key} -> {user[key]}")

# lname -> Bar
# fname -> Foo