De-tupleizing a list

John Connor john.theman.connor at gmail.com
Tue Apr 26 06:29:31 CEST 2011


itertools can help you do this too:

import itertools
tl = [('0A',), ('1B',), ('2C',), ('3D',)]

itertools.chain.from_iterable(tl)
<itertools.chain object at 0x11f7ad0>

list(itertools.chain.from_iterable(tl))
['0A', '1B', '2C', '3D']


Checkout http://docs.python.org/library/itertools.html#itertools.chain
for more info.

On Mon, Apr 25, 2011 at 11:08 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> Gnarlodious <gnarlodious at gmail.com> writes:
>> 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',...
>
> Try:
>
>    tlist = [('0A',), ('1B',), ('2C',), ('3D',)]
>    alist = [x for (x,) in tlist]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list