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


Groups > comp.lang.python > #30976

Re: Unpaking Tuple

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <thbach@students.uni-mainz.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.072
X-Spam-Evidence '*H*': 0.86; '*S*': 0.00; 'python': 0.09; 'sat,': 0.15; "'bar']": 0.16; 'head,': 0.16; 'oct': 0.16; 'stumbled': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'please?': 0.22; 'split': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; "d'aprano": 0.29; 'steven': 0.29; 'tail': 0.29; 'could': 0.32; 'to:addr:python-list': 0.33; 'charset:us-ascii': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'sure': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'content-disposition:inline': 0.60; 'thomas': 0.62; 'more': 0.63; 'it!': 0.64; "'foo'": 0.84; 'received:10.94': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=uni-mainz.de; i=@uni-mainz.de; q=dns/txt; s=ironport; t=1349732829; x=1381268829; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=gimljn93F34j0IlC/HIr+G+5/i7AuluUnfkgpvG9MkM=; b=QO1dbypcYiFc0wR/LnJUwpyJQnbjS9/RPbeotKhhz6iKhpU6fagj+3Ms RfJXlEdOowayFyPEIOKhBbVZ6mAPbROxDeAvQ48OZeG45V1i0SJ1/yhUR 8pCmQV3evaU+6LXpcTb3uXGjiMPvkpbePjZaaNDRRXsobCDvdAHMYI402 Q=;
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AtEEAFJIc1AKXgZQ/2dsb2JhbABFu26ESoIgAQEFOk8LGB4QFCkgiBy6NotPgm9IgXlgA5VqAZAugmAPghU
Date Mon, 8 Oct 2012 23:45:58 +0200
From Thomas Bach <thbach@students.uni-mainz.de>
To <python-list@python.org>
Subject Re: Unpaking Tuple
References <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> <mailman.1898.1349519275.27098.python-list@python.org> <roy-289A2F.08462806102012@news.panix.com> <50704975$0$29978$c3e8da3$5496439d@news.astraweb.com>
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Disposition inline
In-Reply-To <50704975$0$29978$c3e8da3$5496439d@news.astraweb.com>
User-Agent Mutt/1.5.21 (2010-09-15)
X-Originating-IP [88.69.178.148]
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.1970.1349732829.27098.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349732829 news.xs4all.nl 6898 [2001:888:2000:d::a6]:38280
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30976

Show key headers only | View raw


Hi there,

On Sat, Oct 06, 2012 at 03:08:38PM +0000, Steven D'Aprano wrote:
> 
> my_tuple = my_tuple[:4]
> a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4]
> 

Are you sure this works as you expect? I just stumbled over the following:

$ python
Python 3.2.3 (default, Jun 25 2012, 23:10:56) 
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> split = ['foo', 'bar']
>>> head, tail = split if len(split) == 2 else split[0], None
>>> head
['foo', 'bar']
>>> tail
>>> 

I don't get it! Could someone help me, please? Why is head not 'foo'
and tail not 'bar'?

Regards,
	Thomas

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


Thread

Unpaking Tuple sajuptpm <sajuptpm@gmail.com> - 2012-10-06 03:09 -0700
  Re: Unpaking Tuple Chris Rebert <clp2@rebertia.com> - 2012-10-06 03:27 -0700
    Re: Unpaking Tuple Roy Smith <roy@panix.com> - 2012-10-06 08:46 -0400
      Re: Unpaking Tuple Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-06 15:08 +0000
        Re: Unpaking Tuple Thomas Bach <thbach@students.uni-mainz.de> - 2012-10-08 23:45 +0200
        RE: Unpaking Tuple "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-08 22:21 +0000
          Re: RE: Unpaking Tuple Bob Martin <bob.martin@excite.com> - 2012-10-09 07:07 +0100
            Re: Unpaking Tuple Dave Angel <d@davea.name> - 2012-10-09 02:29 -0400
              Re: Unpaking Tuple Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-10-09 10:22 +0300
                Re: mangled messages (was: Unpaking Tuple) Tim Chase <python.list@tim.thechases.com> - 2012-10-09 05:48 -0500
                Re: mangled messages (was: Unpaking Tuple) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-10-09 15:05 +0300
                Re: mangled messages Tim Chase <python.list@tim.thechases.com> - 2012-10-09 09:26 -0500
            Re: Unpaking Tuple Grant Edwards <invalid@invalid.invalid> - 2012-10-09 14:11 +0000
            RE: RE: Unpaking Tuple "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-09 16:40 +0000
            Re: Unpaking Tuple Robert Miles <robertmiles@teranews.com> - 2012-11-18 19:14 -0600
            Re: Unpaking Tuple Hans Mulder <hansmu@xs4all.nl> - 2012-11-19 02:56 +0100
  Re: Unpaking Tuple woooee <woooee@gmail.com> - 2012-10-07 10:58 -0700
    Re: Unpaking Tuple Terry Reedy <tjreedy@udel.edu> - 2012-10-07 16:03 -0400

csiph-web