[Python] Declarations of list or nested lists

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    What is this declaration?

    lists are declared using [ but these contain key-value pairs as seen with the use of {}. It's confusing. list with {} brackets with a pair of two items forming one.

    players = [
    {"name": "Rolf", "numbers": {1, 3, 5, 7, 9, 11}},
    {"name": "Charlie", "numbers": {2, 7, 9, 22, 10, 5}},
    {"name": "Anna", "numbers": {13, 14, 15, 16, 17, 18}},
    {"name": "Jen", "numbers": {19, 20, 12, 7, 3, 5}}
    ]


    How does player in players have a "numbers" index?

    for player in players: # Go over each player
    matched_numbers = len(player["numbers"].intersection(lottery_numbers))


    and how does the len function work?

    Continue reading...

Compartilhe esta Página