[Python] Does the way you define nested lists in Python matter? [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    Let's assume that I defined a list list1 as:

    list1 = [[0]*10]*10


    and defined list2 as:

    list2 = [[0]*10 for i in range(10)]


    Aren't these pretty much two equivalent ways of defining a nested list? Is there any reason these two lists would be different in some way?

    Continue reading...

Compartilhe esta Página