list comprehension question
Jeremy Bowers
newsfroups at jerf.org
Mon Mar 25 01:19:46 EST 2002
Tripp Scott wrote:
> 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]
The closest thing I can get is something like this:
[x+float(y)/10 for x in range(10) for y in range(x)]
where the second for statement depends on the first.
How about examples of real input and real output you want? And why are
you asking specifically about list comprehensions? (Are you just trying
to learn about them?) If you're trying to solve a real problem, they may
not be the best solution. (Though the odds are good.).
More information about the Python-list
mailing list