De-tupleizing a list

Chris Angelico rosuav at gmail.com
Tue Apr 26 15:51:01 EDT 2011


On Wed, Apr 27, 2011 at 5:39 AM, Mark Niemczyk <prahamark at gmail.com> wrote:
> (2)    return [item[0] for item in lst]                          #relative time:  106
> (5)    return [x for (x,) in lst]                                      #relative time:  52

Interesting indeed. #5 will of course only work with a tuple of length
1, where most of the others are flexible enough to take the first
element from any length tuple; but the time saving is quite
significant.

Chris Angelico



More information about the Python-list mailing list