Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4021

Re: De-tupleizing a list

References <8dcab23b-6e38-41d0-9591-ef3cbfdbd589@a21g2000prj.googlegroups.com> <7x1v0pmz72.fsf@ruckus.brouhaha.com>
Date 2011-04-25 23:29 -0500
Subject Re: De-tupleizing a list
From John Connor <john.theman.connor@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.827.1303792173.9059.python-list@python.org> (permalink)

Show all headers | View raw


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@nospam.invalid> wrote:
> Gnarlodious <gnarlodious@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
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

De-tupleizing a list Gnarlodious <gnarlodious@gmail.com> - 2011-04-25 20:28 -0700
  Re: De-tupleizing a list CM <cmpython@gmail.com> - 2011-04-25 20:42 -0700
    Re: De-tupleizing a list Gnarlodious <gnarlodious@gmail.com> - 2011-04-25 20:52 -0700
  Re: De-tupleizing a list "Littlefield, Tyler" <tyler@tysdomain.com> - 2011-04-25 21:38 -0600
  Re: De-tupleizing a list Philip Semanchuk <philip@semanchuk.com> - 2011-04-25 23:38 -0400
  Re: De-tupleizing a list Paul Rubin <no.email@nospam.invalid> - 2011-04-25 21:08 -0700
    Re: De-tupleizing a list John Connor <john.theman.connor@gmail.com> - 2011-04-25 23:29 -0500
  Re: De-tupleizing a list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-26 04:59 +0000
    Re: De-tupleizing a list rusi <rustompmody@gmail.com> - 2011-04-25 22:26 -0700
    Re: De-tupleizing a list Gnarlodious <gnarlodious@gmail.com> - 2011-04-26 05:19 -0700
      Re: De-tupleizing a list Algis Kabaila <akabaila@pcug.org.au> - 2011-04-27 04:30 +1000
        Re: De-tupleizing a list Hans Georg Schaathun <hg@schaathun.net> - 2011-04-26 21:11 +0100
          Re: De-tupleizing a list Ethan Furman <ethan@stoneleaf.us> - 2011-04-26 13:37 -0700
            Re: De-tupleizing a list Hans Georg Schaathun <hg@schaathun.net> - 2011-04-26 21:58 +0100
  Re: De-tupleizing a list Raymond Hettinger <python@rcn.com> - 2011-04-26 14:16 -0700
  Re: De-tupleizing a list John Pinner <funthyme@gmail.com> - 2011-04-27 03:56 -0700
    Re: De-tupleizing a list Algis Kabaila <akabaila@pcug.org.au> - 2011-04-28 05:31 +1000

csiph-web