osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposal: named return values through dict initialization and unpacking


On 26 June 2016 at 18:28, Ari Freund via Python-list
<python-list at python.org> wrote:
> Thanks everybody.  There seems to be a lot of resistance to dict unpacking, in addition to the problem with my proposed shorthand dict() initialization syntax pointed out by Steven D'Aprano, so I won't be pursuing this.
> --
> https://mail.python.org/mailman/listinfo/python-list

something like:

a, b, c = my_magic_reordering_func(mydict, ["alpha", "beta", "charlie"])

..is not too far off, altho it is a little repetitive is is trivial to
write in current python and reaches the goal of insulating you from
some degree of change in the return value. can also be extended to
work with namedtuple for example (which you probably should already be
using if you want to return so many arguments that this is a problem,
returning several arguments is already returning a tuple under the
hood afterall)