LoopsΒΆ

Example of using two variables in a for loop to iterate over a list of tuples:

games_won = dict(sara=0, bob=1, tim=5, julian=3, jim=1)

def print_game_stats(games_won=games_won):
    """Loop through games_won's dict k, v pairs (items) and
       print how many games each person has won, pluralize
       'game' based on number"""
    for name, num_games in games_won.items():
        games = "game" if num_games == 1 else "games"
        print(f'{name} has won {num_games} {games}')