Sequence-spreading
gzeljko
gzeljko at sezampro.yu
Tue Mar 20 15:04:48 EST 2001
Joshua Marshall <jmarshal at mathworks.com> wrote in message
news:998ba7$5j7$1 at news.mathworks.com...
> gzeljko <gzeljko at sezampro.yu> wrote:
>
> > 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
>
> Careful here:
>
> >>> x = [[]]*2
> >>> y = [[] for i in range(2)]
> >>> x
> [[], []]
> >>> y
> [[], []]
> >>> x[0] is x[1]
> 1
> >>> y[0] is y[1]
> 0
>
> The first way gives you the same value at each element ("[]" is
> evaluated once), while the second way gives you distinct values ("[]"
> is evaluated for each element).
> --
[Careful]*3
Thanx.
ly-y'rs-gzeljko
More information about the Python-list
mailing list