Re: One-step multiples list generation?

2006-01-06 Thread Xavier Morel
Damien Wyart wrote: Thanks for these important and useful additions, they are very welcome ! In writing my answer I had immutables in mind, but mutables are a bit more dangerous, here... Not *that* much though. The first construct can't be used, but he can use [copy.copy(Foo) for _ in

One-step multiples list generation?

2006-01-03 Thread Efrat Regev
Hello, Suppose I have some non-numerical Foo and would like to create a list of 20 Foo-s. Is there a one-step method (not a loop) of doing so? E.g., something like [Foo * 20] (which is obviously not the right way) that would create [Foo, Foo, Foo, ...,Foo]. I tried looking through the

Re: One-step multiples list generation?

2006-01-03 Thread Damien Wyart
* Efrat Regev [EMAIL PROTECTED] in comp.lang.python: Suppose I have some non-numerical Foo and would like to create a list of 20 Foo-s. Is there a one-step method (not a loop) of doing so? Maybe : [ Foo ] * 20 or, more verbose, [ Foo for _ in range(20) ] ? -- DW --

Re: One-step multiples list generation?

2006-01-03 Thread Rocco Moretti
Rocco Moretti wrote: Damien Wyart wrote: * Efrat Regev [EMAIL PROTECTED] in comp.lang.python: Suppose I have some non-numerical Foo and would like to create a list of 20 Foo-s. Is there a one-step method (not a loop) of doing so? Maybe : [ Foo ] * 20 or, more verbose, [ Foo for _

Re: One-step multiples list generation?

2006-01-03 Thread Rocco Moretti
Damien Wyart wrote: * Efrat Regev [EMAIL PROTECTED] in comp.lang.python: Suppose I have some non-numerical Foo and would like to create a list of 20 Foo-s. Is there a one-step method (not a loop) of doing so? Maybe : [ Foo ] * 20 or, more verbose, [ Foo for _ in range(20) ] If

Re: One-step multiples list generation?

2006-01-03 Thread Damien Wyart
Thanks for these important and useful additions, they are very welcome ! In writing my answer I had immutables in mind, but mutables are a bit more dangerous, here... -- DW -- http://mail.python.org/mailman/listinfo/python-list

Re: One-step multiples list generation?

2006-01-03 Thread Efrat Regev
Damien Wyart wrote: * Efrat Regev [EMAIL PROTECTED] in comp.lang.python: Suppose I have some non-numerical Foo and would like to create a list of 20 Foo-s. Is there a one-step method (not a loop) of doing so? Maybe : [ Foo ] * 20 or, more verbose, [ Foo for _ in range(20) ] ?

Re: One-step multiples list generation?

2006-01-03 Thread Steven D'Aprano
On Tue, 03 Jan 2006 19:21:32 +0100, Damien Wyart wrote: Thanks for these important and useful additions, they are very welcome ! In writing my answer I had immutables in mind, but mutables are a bit more dangerous, here... Mutables are easy to deal with using the copy module and list