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

Dict comprehension

people = {
    'Foo':       123,
    'Bar':       456,
    'SnowWhite': 7,
}

doubles = { k:v*2 for (k, v) in people.items() }
print(doubles)  # {'Foo': 246, 'Bar': 912, 'SnowWhite': 14}

Output: