Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #110532
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Proposal: named return values through dict initialization and unpacking |
| Date | 2016-06-26 18:17 +0000 |
| 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> |
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