list comprehensions whats happening here
Terry Reedy
tjreedy at udel.edu
Fri Apr 13 22:14:22 EDT 2001
> For example,
>
> >>> [[i,j] for i in (0,) for j in ('a', 'b', 'c')]
> [[0, 'a'], [0, 'b'], [0, 'c']]
>
> prepends 0 to all members of the list;
> I also believe that the idiom above will turn out
> to be the fastest way to prepend all elements of a list with something,
> without using any extra space, or calling any user defined function.
Uh, no.
[[0,j] for j in ('a','b','c')] is much cleaner and faster. Methinks
turning a constant into a pseudovariable is the wrong way to go.
Terry J. Reedy
More information about the Python-list
mailing list