Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7566 > unrolled thread

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

Started bySherjilOzair <sherjilozair@gmail.com>
First post2011-06-13 15:37 -0700
Last post2011-06-14 00:38 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  I want this to work. [[]] * n SherjilOzair <sherjilozair@gmail.com> - 2011-06-13 15:37 -0700
    Re: I want this to work. [[]] * n Chris Angelico <rosuav@gmail.com> - 2011-06-14 08:51 +1000
      Re: I want this to work. [[]] * n SherjilOzair <sherjilozair@gmail.com> - 2011-06-14 00:38 -0700

#7566 — I want this to work. [[]] * n

FromSherjilOzair <sherjilozair@gmail.com>
Date2011-06-13 15:37 -0700
SubjectI want this to work. [[]] * n
Message-ID<45f5e602-b196-43b4-97cd-5fa8d4b7058c@h12g2000pro.googlegroups.com>
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 ?

[toc] | [next] | [standalone]


#7568

FromChris Angelico <rosuav@gmail.com>
Date2011-06-14 08:51 +1000
Message-ID<mailman.201.1308005500.11593.python-list@python.org>
In reply to#7566
On Tue, Jun 14, 2011 at 8:37 AM, SherjilOzair <sherjilozair@gmail.com> wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#7592

FromSherjilOzair <sherjilozair@gmail.com>
Date2011-06-14 00:38 -0700
Message-ID<9c5ca2ca-fc58-40b8-b009-3af9ae9c8e1f@y7g2000prk.googlegroups.com>
In reply to#7568
Thanks. This works. :)

Regards,
Sherjil Ozair

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web