Will OrderedDict become redundant in Python 3.7?

后端 未结 1 395
情书的邮戳
情书的邮戳 2020-11-30 00:42

From the Python 3.7 changelog:

the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language

相关标签:
1条回答
  • 2020-11-30 01:25

    No it won't become redundant in Python 3.7 because OrderedDict is not just a dict that retains insertion order, it also offers an order dependent method, OrderedDict.move_to_end(), and supports reversed() iteration*.

    Moreover, equality comparisons with OrderedDict are order sensitive and this is still not the case for dict in Python 3.7, for example:

    >>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)]) 
    False
    >>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)]) 
    True
    

    Two relevant questions here and here.

    * Support for reversed() iteration of regular Python dict is added for Python 3.8, see issue33462

    0 讨论(0)
提交回复
热议问题