3 ms·
>>> { 'a' : 1 } | { 'a' : 2 } ISTM the most logical result would be: { 'a' : { 1, 2 } } ...but I could certainly understand throwing an exception.
by jessaustin 8y ago
>>> { 'a' : 1 } | { 'a' : 2 }
ISTM the most logical result would be:
{ 'a' : { 1, 2 } }
...but I could certainly understand throwing an exception.
- xiao_haozi 8y agoWhile I see your point, I don't think this makes sense historically. Dictionaries never supported such behavior before so you'd be introducing a new core concept to a dictionary. But moreover, you'd be changing the type of the value only on duplicated keys, and what about if you were to add another value of 2 to a? Are you making this a set, and why? I think it would come with too many caveats and assumptions in the PEP. I'm not saying you have a bad idea/logic here, just that I'm not sure it's the best thing for the dict.
- dan-robertson 8y agoNote that this forgets the order of the arguments, which may not be desirable
- kqr 8y agoIf the property we want to achieve is "a | b == b | a" we necessarily have to forget the order of the arguments.