|
|
Log in / Subscribe / Register

Toward a conclusion for Python dictionary "addition"

Toward a conclusion for Python dictionary "addition"

Posted Jan 9, 2020 13:21 UTC (Thu) by mina86 (guest, #68442)
Parent article: Toward a conclusion for Python dictionary "addition"

Is there an example of a type where pipe operator is not reflective (as in ‘x | y’ yields different result to ‘y | x’)? Preferring ‘|’ over ‘+’ seems strange to me as it would create an unnecessary precedence. Using plus wouldn’t create such a precedence and programmers are already used to addition not being reflective for all types.


to post comments

Toward a conclusion for Python dictionary "addition"

Posted Jan 9, 2020 13:49 UTC (Thu) by maltekraus (subscriber, #129184) [Link] (1 responses)

Sets: {1} | {True} gives {1}, whereas {True} | {1} gives {True}.

Toward a conclusion for Python dictionary "addition"

Posted Jan 9, 2020 18:50 UTC (Thu) by NYKevin (subscriber, #129325) [Link]

I'm not entirely convinced that counts:

Python 3.7.5rc1 (default, Oct  2 2019, 04:19:31) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 == True
True
>>> {1} == {True}
True
>>> {'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'} == {'cheese': 3, 'aardvark': 'Ethel', 'spam': 1, 'eggs': 2}
False


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds