
On Fri, May 27, 2016 at 9:36 AM, Chris Barker <chris.barker@noaa.gov> wrote:
On Fri, May 27, 2016 at 9:17 AM, Steven D'Aprano <steve@pearwood.info> wrote:
# apologies for breaking my own rule about realistic names fee, fi, fo, fum = mydict.getmany('fee', 'fi', 'fo', 'fum')
so how again is the much better than:
Isn't this the status quo? a, b, c = [mapping[k] for k in ('a', 'b', 'c')]
the objection to that was that it gets ugly when you've got longer, more realistic names (and maybe more of them.)
fee, fi, fo, fum = [mapping[k] for k in ('fee', 'fi', 'fo', 'fum')]
only a little more typing, and in both cases, you need to specify the names twice.
(of course, they don't need to be the same names...)
Honestly I don't like the comprehension version much; it reeks of cleverness. The advantage of the getnamy() spelling is that you can Google for it more easily. (But I don't know how it would handle nested unpacking, which some have said is an important use case to warrant adding complexity to the language.) If this was a Dropbox code review I'd say rewrite it as fee = mapping['fee'] fi = mapping['fi'] etc. -- then nobody will have any trouble understanding what it does. -- --Guido van Rossum (python.org/~guido)