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


Groups > comp.lang.python > #4063

Re: De-tupleizing a list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <akabaila@pcug.org.au>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'received:localnet': 0.07; 'python': 0.07; 'ah,': 0.09; 'pm,': 0.11; '>>>': 0.12; '25,': 0.12; 'wrote:': 0.14; '10:59': 0.16; 'iterator': 0.16; 'quicker': 0.16; 'wrap': 0.19; 'cc:2**0': 0.20; 'help.': 0.22; 'subject:list': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'module,': 0.23; 'instead': 0.26; 'thanks': 0.29; 'cc:addr:gmail.com': 0.31; 'to:addr:python-list': 0.32; 'module': 0.33; 'using': 0.34; 'header:User-Agent:1': 0.35; 'running': 0.36; 'received:au': 0.36; 'list,': 0.36; 'think': 0.36; 'useful': 0.37; 'apr': 0.38; 'steven': 0.38; 'url:org': 0.38; 'url:au': 0.39; 'to:addr:python.org': 0.39; 'works': 0.40; 'map': 0.40; 'would': 0.40; 'header:Message-Id:1': 0.62; '2011': 0.62; 'ready': 0.63; 'tuesday': 0.84
From Algis Kabaila <akabaila@pcug.org.au>
Organization PCUG - Users Helping Users
To python-list@python.org
Subject Re: De-tupleizing a list
Date Wed, 27 Apr 2011 04:30:01 +1000
User-Agent KMail/1.13.5 (Linux/2.6.35-25-generic-pae; KDE/4.5.1; i686; ; )
References <8dcab23b-6e38-41d0-9591-ef3cbfdbd589@a21g2000prj.googlegroups.com> <4db6514e$0$29978$c3e8da3$5496439d@news.astraweb.com> <4cb20ed0-c766-4bd8-8d00-762208d92d14@r33g2000prh.googlegroups.com>
In-Reply-To <4cb20ed0-c766-4bd8-8d00-762208d92d14@r33g2000prh.googlegroups.com>
MIME-Version 1.0
Content-Type Text/Plain; charset="iso-8859-1"
Content-Transfer-Encoding 7bit
Cc Gnarlodious <gnarlodious@gmail.com>
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.856.1303842605.9059.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 82.94.164.166
X-Trace 1303842605 news.xs4all.nl 41103 [::ffff:82.94.164.166]:58541
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4063

Show key headers only | View raw


On Tuesday 26 April 2011 22:19:08 Gnarlodious wrote:
> On Apr 25, 10:59 pm, Steven D'Aprano wrote:
> > 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().
> 
> Ah, thanks for that tip. Also works for outputting a tuple:
> list_of_tuples=[('0A',), ('1B',), ('2C',), ('3D',)]
> 
> #WRONG:
> (x for (x,) in list_of_tuples)
> <generator object <genexpr> at 0x1081ee0>
> 
> #RIGHT:
> tuple(x for (x,) in list_of_tuples)
> 
> Thanks everyone for the abundant help.
> 
> -- Gnarlie

I think you already have the following:
>>> t = [('0A',), ('1B',), ('2C',), ('3D',)]
>>> ls = [v[0] for v in t]
>>> ls
['0A', '1B', '2C', '3D']
>>> 

I would prefer that to using a ready made module,  as it would 
be quicker than learning about the module,  OTH, learning about 
a module may be useful for other problems.  A standard dilema...

The above quote of code is in Idle3, running Python 3.1.

OldAl.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf

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