triptoe
August 23rd, 2007, 01:42 AM
hey I have a problem..
I have a list and i want to make 6 lists inside of it (actually more)
when i declare it like this:
list = [[1],[1],[1],[1],[1],[1]]
it works fine... BUT when i do this
list = [[1]] * 6
it makes 6 lists inside of it, however when i modify each element with append... instead of adding a value to the individual index, it adds it to each one!! for instance:
list[0].append(1)
will look like this: ([1,1],[1,1],[1,1],[1,1],[1,1],[1,1]
but in the first method it looks like this: ([1,1],[1],[1],[1],[1],[1])
any ideas what is going on ?
I have a list and i want to make 6 lists inside of it (actually more)
when i declare it like this:
list = [[1],[1],[1],[1],[1],[1]]
it works fine... BUT when i do this
list = [[1]] * 6
it makes 6 lists inside of it, however when i modify each element with append... instead of adding a value to the individual index, it adds it to each one!! for instance:
list[0].append(1)
will look like this: ([1,1],[1,1],[1,1],[1,1],[1,1],[1,1]
but in the first method it looks like this: ([1,1],[1],[1],[1],[1],[1])
any ideas what is going on ?