Simple list.append() question

Kevin Cazabon kcazabon at home.com
Tue Apr 25 01:57:03 EDT 2000


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([])


Kevin.

"Bjorn Pettersen" <bjorn at roguewave.com> wrote in message
news:39046FA2.603EAFE5 at roguewave.com...
> Jeff Massung wrote:
> >
> > I'm just learning, but my guess is this:
> >
> > >>> l=[[]]*3
> > >>> l
> > [[], [], []]
> > >>> l[0].append(3)
> > >>> l
> > [[3], [3], [3]]
> > >>> id(l[0])
> > 8539088
> > >>> id(l[1])
> > 8539088
> > >>> id(l[2])
> > 8539088
> > >>>
> >
> > The *3 just made three lists pointing to the same place. I don't know
how to
> > get what you want tho ;) someone else can enlighten me, too :).
>
> One way is:
>
> x = map(lambda x:[], [[]]*3)
>
> although there has to be a prettier way...
>
> -- bjorn
>





More information about the Python-list mailing list