Suggestion: make sequence and map interfaces more similar

Steven D'Aprano steve at pearwood.info
Wed Mar 30 08:27:58 EDT 2016


On Wed, 30 Mar 2016 10:21 pm, Jussi Piitulainen wrote:

> Ok, safer to say that some many-to-one mappings are not surjective.

Can you give an example of a Python dict which is not surjective?

Or an example of something which obeys the Mapping ABC which is not
surjective?

Artificial and contrived examples such as this do not count:

class MyDict(dict):
    def values(self):
        for value in super().values():
            yield value
        yield object()  # It's a value without a key!




-- 
Steven




More information about the Python-list mailing list