Suggestion: make sequence and map interfaces more similar

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Wed Mar 30 10:38:19 EDT 2016


Marko Rauhamaa writes:

> Steven D'Aprano:
>
>> 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?
>
> Depends on the codomain. The values() method gives the range.
>
> If you have an ordinary Python dictionary that maps strings to strings,
> it will be neither total nor surjective. Since there are strings that
> are not among the keys (not total) and there are strings that are not
> among the values (not surjective).
>
> You can of course equate keys() with the domain and values() with the
> range, in which case the whole discussion becomes nonsensical.
>
> However, a collections.defaultdict instance can be both total and
> surjective in the meaningful senses of the words.

The cited Wikipedia article uses "image" for what Marko here calls
"range" (unfortunately it also calls individual values "images" (and the
elements of the domain and codomain, "expressions"), and "range" is also
sometimes used to mean codomain :).

I'm just pointing this out because range aka image is a key concept
here, together with codomain.

<https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection>



More information about the Python-list mailing list