Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #110532
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Michael Selik <michael.selik@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Proposal: named return values through dict initialization and unpacking |
| Date | Sun, 26 Jun 2016 18:17:01 +0000 |
| Lines | 23 |
| Message-ID | <mailman.10.1466965034.2358.python-list@python.org> (permalink) |
| References | <CALyUfwV9jO0xjSz_Qhk3ox=rJCcAsBE+iU2WzcmXtCEwZS+xEQ@mail.gmail.com> <mailman.0.1466494641.11516.python-list@python.org> <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> <CAGgTfkOST9Go5jVmFjKd=GsLW=NLiUo+Udsne5OaMpoNf5PoWA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de Qc23Wgw8qU1n8OgHiKD3jADKwJhQE/CMOs6OfhRlmjow== |
| Return-Path | <michael.selik@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '21,': 0.07; 'width': 0.07; "ain't": 0.09; 'dict': 0.09; 'unpacking': 0.09; 'syntax': 0.13; '2016': 0.16; 'readable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:values': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'width,': 0.16; 'wrote:': 0.16; 'skip:{ 20': 0.18; 'to:2**1': 0.21; 'either.': 0.22; 'keys': 0.22; 'subject:skip:i 10': 0.22; 'uses.': 0.22; 'header:In-Reply-To:1': 0.24; 'sense': 0.26; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'raise': 0.29; 'maybe': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'quite': 0.35; 'expected': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'skip:v 20': 0.38; 'names': 0.38; 'application': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'more': 0.63; 'freund': 0.84; 'nicely.': 0.84; 'subject:Proposal': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=tL3DeVXKM+CcF4Jxnl4e/mltGzdKYn5z5rJGJIRJsYY=; b=qMf26/ZHj+TkzRsBwxxo0MBU3EJSv6P08GtLl1LYEskbGBqSabc3m2wWDptLBGFQ96 Crppol6AmBzSaPUO93Bo/uvnuB7wfgESUYCmDU33H0x0Csfg5N9olpSArK57NqlAg3Ih hRzPMNfMZyQNeBo6sm9pqVdSb7rHFelIz7o57bONu/0eg8FtgEGF4Wl4ODd4dRh5hmJc jTSdoDiiqi7+gwx/KNpKbX2bWSbcMtEApLwV5AZWO3wxMVs7nc/CgphQj8ldfeZEbDjx EI/ymkeqPesbwG/qkxIYffB62erdw8ug2I0wJFILhFcOWowVXVDUV6eKIfNVFeYAlolf IliA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=tL3DeVXKM+CcF4Jxnl4e/mltGzdKYn5z5rJGJIRJsYY=; b=DUkBIcvrDKh261gvBJQ34uMR+fzvj0pygkj/mhhmtquzYg5vjrLDALJC4OGd4rcWnJ faCSo5yKkO3Lk4PPag5zVDFEWIoxuMQxwW0jhPTFf0MaeA+9UUov0D1CDgwmQVljew3Z JH4bR+0ZNGwapAkA+oPqYkseEkjJgVeOoxRbLfsbhNYGfP2h9CtC1qvWYiFEyFCKSCBu fKCgvtuUHTbtsEApmAFTsA+k/HWTStWUjMxckVJG8FeUvQLoe8upi2FmCuK5so0eanpp ZH2S6g52+sG0YRBwYpO18/an1eOJYoSjqXX3lTu1NmPFJh+7YSLo/IcDV+M/nVP6bnVK rK8Q== |
| X-Gm-Message-State | ALyK8tIQCFDU/Rsn+9P/w9qgNppE/oIx7/qBsWVCA0c6RD85p6mwhkfFr3nMjqfGdJIRjfFNVG+fcqW/LUzsWg== |
| X-Received | by 10.55.43.229 with SMTP id r98mr18757909qkr.62.1466965030843; Sun, 26 Jun 2016 11:17:10 -0700 (PDT) |
| In-Reply-To | <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <CAGgTfkOST9Go5jVmFjKd=GsLW=NLiUo+Udsne5OaMpoNf5PoWA@mail.gmail.com> |
| X-Mailman-Original-References | <CALyUfwV9jO0xjSz_Qhk3ox=rJCcAsBE+iU2WzcmXtCEwZS+xEQ@mail.gmail.com> <mailman.0.1466494641.11516.python-list@python.org> <5769eb4a$0$1610$c3e8da3$5496439d@news.astraweb.com> |
| Xref | csiph.com comp.lang.python:110532 |
Show key headers only | View raw
On Tue, Jun 21, 2016 at 9:41 PM Steven D'Aprano <steve@pearwood.info> wrote:
> On Tue, 21 Jun 2016 05:34 pm, Ari Freund wrote:
> > var3, var1, var2 = **d
>
> But I don't want to use the key names your function uses. I want to
> use names which makes sense for my application
>
Note that my dict unpacking syntax proposal would solve this quite nicely.
{'var1': width, 'var2': counter, 'var3': aardvark} = d
But the current syntax ain't so bad either. Maybe it's even better, more
readable despite being less concise.
expected = {'var1', 'var2', 'var3'}
excess = d.keys() - expected
if excess:
raise ValueError('unexpected keys {!r}'.format(excess))
width = d['var1']
counter = d['var2']
aardvark = d['var3']
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Proposal: named return values through dict initialization and unpacking Ari Freund <arief@google.com> - 2016-06-21 10:34 +0300
Re: Proposal: named return values through dict initialization and unpacking Steven D'Aprano <steve@pearwood.info> - 2016-06-22 11:35 +1000
Re: Proposal: named return values through dict initialization and unpacking Michael Selik <michael.selik@gmail.com> - 2016-06-26 18:17 +0000
Re: Proposal: named return values through dict initialization and unpacking arief@google.com - 2016-06-26 08:28 -0700
Re: Proposal: named return values through dict initialization and unpacking Joonas Liik <liik.joonas@gmail.com> - 2016-06-26 18:50 +0300
csiph-web