Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85217
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'result,': 0.07; 'cc:addr :python-list': 0.11; 'def': 0.12; 'cleaner': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'lambda:': 0.16; 'typeerror:': 0.16; 'unpack': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; '"",': 0.31; '>>>>': 0.31; 'file': 0.32; '(most': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'yield': 0.36; 'list': 0.37; 'rather': 0.38; 'recent': 0.39; '2015': 0.84; 'technically': 0.84; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=ttxHBEPbrY3j+uaH5QU0pnLJLLAwbYXp5obqmDb9zvM=; b=b3NZy4vhdU5kjf5Dj+9BsEp995szPdZSN/Mq1v5KVR6Es+wzbqmeEJofWSV9B9LOp/ ycBugaHuM8b4s2wfmA/g8LwW4XkMrB3PepVx+iuhTZ2+V+hUsE8/E5oQNB4RH6dQoydE hosSHPsbYygL/IS/Whs9yryam1WfLayeln8Ael/47TsGK3uOOMPsB0j8BTI0oVlgqtrE 6k2DFtCAm/YADDqJLQh4gLSTN4dJwdegbj9ygfYb85jysipYSlvEb7I7K2Vt2Q10w28O IstTXw0M9fKhjCe10ZSrljH4EiWhfIoQfdkjldq+DsJmMe0wlRDUOCttGLnu95aGQI16 cN9g== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.52.200 with SMTP id k8mr2190029icg.26.1423062266588; Wed, 04 Feb 2015 07:04:26 -0800 (PST) |
| In-Reply-To | <657497900.499606.1423060711538.JavaMail.yahoo@mail.yahoo.com> |
| References | <CAPTjJmpqx1Cmm89Lg6-XL4-xdM+xD6=GHKvWb2zYTe4=11ZPPg@mail.gmail.com> <657497900.499606.1423060711538.JavaMail.yahoo@mail.yahoo.com> |
| Date | Thu, 5 Feb 2015 02:04:26 +1100 |
| Subject | Re: meaning of: line, = |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.18465.1423062269.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1423062269 news.xs4all.nl 2868 [2001:888:2000:d::a6]:49406 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:85217 |
Show key headers only | View raw
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; but if it's something iterable but not subscriptable, the unpack will still work. >>> def f(): yield 42 ... >>> result, = f() >>> result 42 >>> result = f()[0] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'generator' object is not subscriptable ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: meaning of: line, = Chris Angelico <rosuav@gmail.com> - 2015-02-05 02:04 +1100
csiph-web