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

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top