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
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to