[Python] Dictionary comprehension explanation

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning Python and came across Dictionary Comprehension. Please help me make sense why the output is as follows? I was expecting {1:0,1:1,1:2,1:3,1:4,1:5,2:0,..}

    lst={j:i for i in range(1,11) for j in range(5)} print(lst)

    OUTPUT {1: 4, 2: 4, 3: 4, 4: 4, 5: 4, 6: 4, 7: 4, 8: 4, 9: 4, 10: 4}

    Continue reading...

Compartilhe esta Página