From: kj on 13 Nov 2009 16:26 ....just bit me in the "fuzzy posterior". The best I can come up with is the hideous lol = [[] for _ in xrange(500)] Is there something better? What did one do before comprehensions were available? I suppose in that case one would have to go all the way with lol = [None] * 500 for i in xrange(len(lol)): lol[i] = [] Yikes. 10 miles uphill, both ways... kynn
From: Jon Clements on 13 Nov 2009 16:56 On 13 Nov, 21:26, kj <no.em...(a)please.post> wrote: > ...just bit me in the "fuzzy posterior". The best I can come up with > is the hideous > > lol = [[] for _ in xrange(500)] > > Is there something better? That's generally the accepted way of creating a LOL. > What did one do before comprehensions > were available? I suppose in that case one would have to go all > the way with > > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] > > Yikes. 10 miles uphill, both ways... > >>> lol = map(lambda L: [], xrange(5)) >>> [id(i) for i in lol] [167614956, 167605004, 167738060, 167737996, 167613036] Jon.
From: kj on 13 Nov 2009 18:05 In <6e20a31b-2218-49c5-a32c-5f0147db3172(a)k19g2000yqc.googlegroups.com> Jon Clements <joncle(a)googlemail.com> writes: >>>> lol =3D map(lambda L: [], xrange(5)) >>>> [id(i) for i in lol] >[167614956, 167605004, 167738060, 167737996, 167613036] Oh yeah, map! I'd forgotten all about it. Thanks! kynn
From: Diez B. Roggisch on 14 Nov 2009 03:40 kj schrieb: > ...just bit me in the "fuzzy posterior". The best I can come up with > is the hideous > > lol = [[] for _ in xrange(500)] If you call that hideous, I suggest you perform the same exercise in Java or C++ - and then come back to python and relax.... Diez
From: Paul Rubin on 14 Nov 2009 03:50 kj <no.email(a)please.post> writes: > lol = [None] * 500 > for i in xrange(len(lol)): > lol[i] = [] lol = map(list, [()] * 500)
|
Next
|
Last
Pages: 1 2 Prev: run all scripts in sub-directory as subroutines? Next: python-daemon and upstart |