Suggestion: make sequence and map interfaces more similar

Random832 random832 at fastmail.com
Wed Mar 30 12:52:16 EDT 2016


This discussion is getting a bit distracted from the original request.
Let's look at it from a higher level.

What is being requested, regardless of if you call it a "map interface"
or whatever, is a single way, for sequences and maps... broadly,
anything with a __getitem__, to iterate over all values which one might
pass to __getitem__, so that one might (among other things) call
__setitem__ to mutate the collection.

Like, these are common patterns:

for i, x in enumerate(l):
   # do some stuff, sometimes assign l[i]

for k, v in d.items():
   # do some stuff, sometimes assign d[k]

A way to apply that pattern generically to an object which may be either
a sequence or a mapping might be nice. Or some other way of doing this
operation - maybe a writable iterator like C++ or Java.



More information about the Python-list mailing list