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


Groups > comp.lang.python > #85224

Re: meaning of: line, =

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'result,': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'cleaner': 0.16; 'filename:fname piece:signature': 0.16; 'index.': 0.16; 'iterable': 0.16; 'lambda:': 0.16; 'unpacking': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'thu,': 0.19; 'feb': 0.22; 'header:User- Agent:1': 0.23; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'returned': 0.30; 'checking': 0.33; 'but': 0.35; 'half': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:173': 0.61; 'more': 0.64; '2015': 0.84; 'technically': 0.84
Date Wed, 04 Feb 2015 09:09:59 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: meaning of: line, =
References <CAPTjJmpqx1Cmm89Lg6-XL4-xdM+xD6=GHKvWb2zYTe4=11ZPPg@mail.gmail.com> <657497900.499606.1423060711538.JavaMail.yahoo@mail.yahoo.com> <CAPTjJmrOffgm2t=5JOvO1GC6Z1ASv+URtRoxe7EpxYLmTGwiRA@mail.gmail.com>
In-Reply-To <CAPTjJmrOffgm2t=5JOvO1GC6Z1ASv+URtRoxe7EpxYLmTGwiRA@mail.gmail.com>
Content-Type multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FOGdfN6DBSlic3aWku4UQ6GVtDWf3RKQ6"
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18470.1423069811.18130.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423069811 news.xs4all.nl 2970 [2001:888:2000:d::a6]:56656
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85224

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 02/04/2015 07:04 AM, Chris Angelico wrote:
> On Thu, Feb 5, 2015 at 1:38 AM, Albert-Jan Roskam <fomcl@yahoo.com> wrote:
>> I have also never seen this before, but perhaps this:
>>
>>>>> f = lambda: [42]
>>>>> result, = f()
>>>>> result
>> 42
>>
>> ... is slightly cleaner than this:
>>>>> result = f()[0]
>>>>> result
>> 42
> 
> They're not technically identical. If the thing returned is
> subscriptable (as with your list example), then I would definitely
> subscript it rather than unpacking;

By unpacking you are also double checking that the returned iterable contains exactly one item; more or less will cause
an exception -- you only get half that check if you index.

--
~Ethan~

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


Thread

Re: meaning of: line, = Ethan Furman <ethan@stoneleaf.us> - 2015-02-04 09:09 -0800

csiph-web