list comprehension question
Tripp Scott
tripps81 at yahoo.com
Sun Mar 24 23:19:44 EST 2002
At 25/03/2002 07:37, brueckd at tbye.com wrote:
> > [SOMETHING for x in 1,2,3]
> >
> > and without using side effects like this?
> >
> > result=[]
> > [(result.append(x), result.append(x+1.1)) for x in 1,2,3]
>
>You gotta give us more info on the 1,2,3 part. Does that just represent
>a sequence of integers? If so, you can go with something like:
>
> >>> lo, hi = 1, 3
> >>> [x/2 + 0.1*(x%2) for x in xrange(lo*2, (hi+1)*2)]
thanks for the tip. actually, the essence of what i wanted to
ask was: "can that SOMETHING be a list of more than one elements
which will be _flatly_ added to the result list." as another
example, can i generate this list
[1,1 2,2,2, 3,3,3,3, 4,4]
with a list comprehension that contains one 'for' clause?
t
More information about the Python-list
mailing list