Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85224
| Date | 2015-02-04 09:09 -0800 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18470.1423069811.18130.python-list@python.org> (permalink) |
[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
Re: meaning of: line, = Ethan Furman <ethan@stoneleaf.us> - 2015-02-04 09:09 -0800
csiph-web