Why does the **kwargs mapping compare equal with a differently ordered OrderedDict?

前端 未结 4 421
挽巷
挽巷 2021-01-17 12:00

According to PEP 468:

Starting in version 3.6 Python will preserve the order of keyword arguments as passed to a function. To accomplish this the coll

4条回答
  •  感动是毒
    2021-01-17 12:18

    Regardless of what an “ordered mapping” means, as long as it’s not necessarily OrderedDict, OrderedDict’s == won’t take into account its order. Docs:

    Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests between OrderedDict objects and other Mapping objects are order-insensitive like regular dictionaries. This allows OrderedDict objects to be substituted anywhere a regular dictionary is used.

提交回复
热议问题