Suggestion: make sequence and map interfaces more similar

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


On Thu, 31 Mar 2016 06:07 am, Antoon Pardon wrote:

>> Because fundamentally, it doesn't matter whether dicts are surjections or
>> not. They're still many-to-one mappings, and those mappings between keys
>> and values should not change due to the insertion or deletion of
>> unrelated keys.
> 
> Repeating your opion without further arguments doesn't lend any support
> to that opinion. If within the problem space you are working on, such a
> change would make sense as a step to generate the next mapping from the
> previous one, i don't see what the problem is if one could make use of
> this.


Enough of the hypothetical arguments about what one could do or might do.
Let's see a concrete example of actual real world code used in production,
not a mickey-mouse toy program, where it is desirable that adding or
deleting one key will modify the rest of the keys in the mapping.

Arguing for the sake of arguing about what somebody might want is not
productive. Let's see some actual concrete use cases where you have a
database or mapping between keys and values, say something like this:

mapping = {
 # name: address
 "fred": "123 Smith Street",
 "george": "27 Main Road",
 "sally": "72a Short Street"
 }


where it is desirable to have this behaviour:

# adding a new key
mapping["mary"] = "31 King Street"
# changes the other keys
assert mapping["george"] != "27 Main Road"


No hypothetical cases where somebody might or could want this behaviour. I'm
not interested in "mights" and "coulds". I want to see an actual
application where adding a new key to a mapping is expected to change the
other keys.



-- 
Steven




More information about the Python-list mailing list