Sequence-spreading
Ken Seehof
kens at sightreader.com
Tue Mar 20 14:38:45 EST 2001
Yikes! No!
>>> a = [[]]*3
>>> a
[[], [], []]
>>> a[2].append(4)
>>> a
[[4], [4], [4]]
Be careful, python does lists by reference, so you get multiple
instantiations of the same list.
offsets = [ [] for i in range(pm) ] # is much better!
----- Original Message -----
From: "gzeljko" <gzeljko at sezampro.yu>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Tuesday, March 20, 2001 9:44 AM
Subject: Re: Sequence-spreading
>
> Alex Martelli <aleaxit at yahoo.com> wrote in message
> > offsets = [ [] for i in range(pm) ]
> > for i in range(len(arg)):
> > offsets[i%pm].append(i)
> >
> >
> > Alex
> >
>
> Old syntax yet works:
>
> offsets = [[]]*pm
>
> ly-y'rs-gzeljko
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list