Just curious, nothing more. Why were dictionary magnitude comparisons (> < >= <=
) removed in Python3? What's the reason that brought to delete them?
For example: dictA > dictB
Just curious, nothing more. Why were dictionary magnitude comparisons (> < >= <=
) removed in Python3? What's the reason that brought to delete them?
For example: dictA > dictB
Arbitrary comparison ordering was removed from Python 3, see Ordering Comparisons in the What's New in Python 3.0 documentation.
There is no meaningful natural ordering between dictionaries. Python 2 only pretended there was to play nice with sorting mixed lists, but this only led to enormous confusion.
Take comparing strings with integers for example; integers are always smaller than strings in Python:
>>> 10 < "10"
True
Many a beginner will try to compare strings with integers anyway; it is natural to use number = raw_input('Pick a number! ')
and then try to compare this with an integer; and sometimes this will look like it is working! In Python 3 this is now an error.
The same applies to the majority of objects; unless they explicitly define comparison methods (__lt__
, __gt__
, etc.) the types are not orderable. This includes dictionaries.