Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4021
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <john.theman.connor@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'sqlite': 0.07; 'pm,': 0.11; '25,': 0.12; 'received:74.125.82.174': 0.12; 'received:mail- wy0-f174.google.com': 0.12; 'wrote:': 0.14; 'pythonic': 0.16; 'checkout': 0.20; 'writes:': 0.20; 'subject:list': 0.22; 'header :In-Reply-To:1': 0.22; 'loop': 0.22; 'mon,': 0.22; 'skip:i 30': 0.23; 'skip:l 30': 0.25; 'url:mailman': 0.27; 'message- id:@mail.gmail.com': 0.28; 'query': 0.29; 'list': 0.30; 'url:library': 0.31; 'paul': 0.32; 'import': 0.32; 'to:addr :python-list': 0.32; 'url:listinfo': 0.33; 'url:docs': 0.33; 'try:': 0.35; 'url:python': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'help': 0.39; 'returning': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; '2011': 0.62; '11:08': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=HL53WwKUkgb8Nrjod8tPRMbrExqJdeknJ9ayosy6buA=; b=neS1Swvq/SZGMfNTbc9QK5bDogbdil1L1h6YRfBJuWlSCSCKZ5wH+UP/X741epu+CO UTapd2FVEJ4r2xSNXurAQP91bkFkyPZi+vQH/YGEfrls39XIdD+W5IlaLmzzvKxSgY1/ Yx7EZIpALTb/Z7JRTLXm8cu3K29e29wI4Cc6M= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=nW/k9beD0HvoDXsfYe07p2qdkf0nGuzEYR3+SrpK3k5UE6XWDRt4nBpJzjlJQo7Npo iPUxM4A7G+sD81HrTyuUdNvnyglc02158dFnlPc5eZ5WSNb82Yp0keLLkciMvpe9ST3Y 3Tgm+OmNSAtVEDdvdDEng5f2Rxv4sxRIqU0WU= |
| MIME-Version | 1.0 |
| In-Reply-To | <7x1v0pmz72.fsf@ruckus.brouhaha.com> |
| References | <8dcab23b-6e38-41d0-9591-ef3cbfdbd589@a21g2000prj.googlegroups.com> <7x1v0pmz72.fsf@ruckus.brouhaha.com> |
| Date | Mon, 25 Apr 2011 23:29:31 -0500 |
| Subject | Re: De-tupleizing a list |
| From | John Connor <john.theman.connor@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.827.1303792173.9059.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1303792173 news.xs4all.nl 65870 [::ffff:82.94.164.166]:44296 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4021 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar
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