gpt4 book ai didi

python - 为什么 Python 字典不统一?

转载 作者:太空狗 更新时间:2023-10-29 17:26:22 25 4
gpt4 key购买 nike

看完this question ,我注意到 S. Lott 可能喜欢使用“ordered defaultdict”,但它不存在。现在,我想知道:为什么我们在 Python 中有这么多的字典类?

  • 字典
  • blist.sorteddict
  • collections.OrderedDict
  • collections.defaultdict
  • weakref.WeakKeyDictionary
  • weakref.WeakValueDictionary
  • 其他人?

为什么没有这样的东西,

dict(initializer=[], sorted=False, ordered=False, default=None, 
weak_keys=False, weak_values=False)

统一一切,并提供所有有用的组合?

最佳答案

一个问题是进行此更改会破坏向后兼容性,因为现在存在这种类型的构造函数用法:

>>> dict(one=1, two=2)
{'two': 2, 'one': 1}

关于python - 为什么 Python 字典不统一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6602816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com