De-tupleizing a list
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Apr 26 00:59:58 EDT 2011
On Mon, 25 Apr 2011 20:28:22 -0700, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a list
> like this?:
>
> ['0A', '1B', '2C', '3D',...
Others have pointed you at a list comprehension, but just for completion,
there's also this:
from operator import itemgetter
map(itemgetter(0), list_of_tuples)
In Python 3, map becomes lazy and returns an iterator instead of a list,
so you have to wrap it in a call to list().
--
Steven
More information about the Python-list
mailing list