Suggestion: make sequence and map interfaces more similar

Marco S. mail.python.org at marco.sulla.e4ward.com
Tue Mar 22 15:54:40 EDT 2016


I noticed that the sequence types does not have these methods that the map
types  has: get(), items(), keys(), values().

It could seem useless to have them for sequences, but I think it will ease
the creation of functions and methods that allow you to input a generic
iterable as parameter, but needs to use one of these methods in case the
parameter is a map.

In one word, it will facilitate duck typing.

For the same reason, I would suggest the introduction of a new map type,
vdict, a dict that by default iterates over values instead over keys. So a
vdict object "d" wiil have iter(d) == iter(d.values()), and should also
have a count() method, like sequence types.

Indeed sequences are, in my humble opinion, a specialized case of maps,
when keys are numeric only, are always contiguous without gaps and start
from 0. This way we will have a simpler way to let people to use sequences
or maps indifferently, and let the code untouched.



More information about the Python-list mailing list