| Store | Cart

Re: [Python-Dev] PEP 469: Restoring the iterkeys/values/items() methods

From: Greg Ewing <greg...@canterbury.ac.nz>
Sun, 20 Apr 2014 11:46:08 +1200
Stephen J. Turnbull wrote:
> Benjamin Peterson writes:> >  > > I suppose there's no way to get the compiler to both make "for x in d">  > > work as above, and make "for k, v in d" be equivalent to Python 2's>  > > "for k, v in d.iteritems()"?> > it would change the meaning of currently correct> programs, so it's a non-starter.

Maybe what's wanted is a function analogous to enumerate() for
mappings instead of sequences. Picking a semi-arbitrary name
for now:

    for k, v in tabulate(d):
       ...

It could be special-cased to recognise dicts and do the appropriate
thing for the Python version concerned. If it doesn't recognise the
type, it would fall back to a generic implementation like

    for k in d:
       v = d[k]:
          ...

-- 
Greg
_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Nick Coghlan Apr 19, 2014 02:31 am
Benjamin Peterson Apr 19, 2014 03:08 am
Nick Coghlan Apr 19, 2014 02:44 pm
Antoine Pitrou Apr 19, 2014 02:47 pm
Guido van Rossum Apr 19, 2014 02:52 pm
Nick Coghlan Apr 19, 2014 04:17 pm
Guido van Rossum Apr 19, 2014 04:35 pm
Donald Stufft Apr 19, 2014 05:16 pm
Nick Coghlan Apr 21, 2014 05:39 am
Terry Reedy Apr 21, 2014 07:34 am
Armin Rigo Apr 21, 2014 07:41 am
Kristján Valur Jónsson Apr 21, 2014 02:04 pm
Luca Sbardella Apr 21, 2014 08:02 pm
Ethan Furman Apr 21, 2014 03:23 pm
Stephen J. Turnbull Apr 19, 2014 04:30 pm
Benjamin Peterson Apr 19, 2014 04:33 pm
Stephen J. Turnbull Apr 19, 2014 05:31 pm
Greg Ewing Apr 19, 2014 11:46 pm
Stephen J. Turnbull Apr 20, 2014 12:56 am
Terry Reedy Apr 20, 2014 04:03 am
Steven DAprano Apr 19, 2014 04:25 am
Nick Coghlan Apr 19, 2014 02:38 pm
Steven DAprano Apr 20, 2014 02:49 am
Paul Moore Apr 20, 2014 11:37 am
Tres Seaver Apr 20, 2014 03:04 pm
Stephen J. Turnbull Apr 21, 2014 05:21 am
Markus Unterwaditzer Apr 20, 2014 12:06 pm
Nick Coghlan Apr 20, 2014 01:55 pm
Terry Reedy Apr 19, 2014 04:35 am
Antoine Pitrou Apr 19, 2014 09:35 am
Kristján Valur Jónsson Apr 19, 2014 11:41 am
Antoine Pitrou Apr 19, 2014 01:04 pm
Steven DAprano Apr 19, 2014 01:14 pm
Ezio Melotti Apr 19, 2014 04:28 pm
Nick Coghlan Apr 19, 2014 06:48 pm
Kristján Valur Jónsson Apr 20, 2014 03:07 pm
Steven DAprano Apr 20, 2014 05:04 pm
Devin Jeanpierre Apr 20, 2014 08:03 pm
Steven DAprano Apr 21, 2014 01:38 am
Kristján Valur Jónsson Apr 21, 2014 02:02 pm
Kristján Valur Jónsson Apr 20, 2014 07:27 pm
Chris McDonough Apr 19, 2014 03:29 pm
Giampaolo Rodola Apr 19, 2014 12:12 pm
Barry Warsaw Apr 19, 2014 10:56 pm
Eric Snow Apr 19, 2014 11:14 pm
Kristján Valur Jónsson Apr 20, 2014 03:34 pm
Nathaniel Smith Apr 19, 2014 12:36 pm
Raymond Hettinger Apr 19, 2014 11:14 pm
Ethan Furman Apr 20, 2014 05:31 am
Mark Lawrence Apr 20, 2014 01:32 pm
Messages in this thread