list comprehension question
Andrew Dalke
dalke at dalkescientific.com
Sun Mar 24 01:11:58 EST 2002
Tripp Scott asked:
>can i generate this list:
>
> [1, 1.1, 2, 2.1, 3, 3.1]
>
>with a list comprehension in a form of this:
>
> [SOMETHING for x in 1,2,3]
>
>and without using side effects like this?
There is no way with list comprehensions which is more
elegant than the standard solution, which is
result = []
for i in 1, 2, 3:
result.extend([i, i + 0.1])
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list