Simple list.append() question
m.faassen at vet.uu.nl
Tue Apr 25 16:38:04 CEST 2000
Kevin Cazabon <kcazabon at home.com> wrote:
> well, if not prettier, why not obfuscate it? q:] Although this isn't
> pretty, I'm sure we can make it a little less intelligable with some work.
> entire_list = ;for i in range(3):entire_list.append()
If you write it the normal way:
entire_list = 
for i in range(3):
It's pretty, readable, flexible, and it works. The only disadvantage is
that it's less short. But I'm willing to pay that price in this situation.
Generally it's a good idea to avoid * on sequences, unless that sequence is
immutable and contains immutable things; i.e. strings. I don't recall
using * on tuples ever, but you can do so safely if the tuple contains
immutable things only.
Is there any useful way to use * on lists that I missed? Usually we want
the copy semantics here, not the reference semantics. Perhaps it's a good
idea to completely forbid * on lists in p3k? Tuples too for all I care.
Then again I may be missing important uses, so enlighten me.
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?
More information about the Python-list