I want this to work. [[]] * n

S

SherjilOzair

I want a list which contains n lists, which are all different. I had
read a page which was about the mutability of lists, and how the *
operator on lists just does a shallow copy. But I can't find it now.
Does anyone know of that page ?

Either way, How to get a list of list, with all original lists ?
 
C

Chris Angelico

I want a list which contains n lists, which are all different. I had
read a page which was about the mutability of lists, and how the *
operator on lists just does a shallow copy. But I can't find it now.
Does anyone know of that page ?

Either way, How to get a list of list, with all original lists ?

Bit more verbose, but...
[[] for i in range(n)]
is effective.

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,333
Messages
2,571,754
Members
48,553
Latest member
Lenore76O

Latest Threads

Top