De-tupleizing a list
Raymond Hettinger
python at rcn.com
Tue Apr 26 17:16:24 EDT 2011
On Apr 25, 8:28 pm, Gnarlodious <gnarlodi... at gmail.com> 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',...
You could unpack the 1-tuple the same way you would with a 2-tuple.
>>> result = [('0A',), ('1B',), ('2C',), ('3D',)]
>>> for elem, in result:
print elem
0A
1B
2C
3D
Raymond
http://twitter.com/raymondh
More information about the Python-list
mailing list