- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的意思不是因为标准这么说,而是它的基本原理。规范说:
If a comma-separated sequence of key/datum pairs is given, they are evaluated from left to right to define the entries of the dictionary: each key object is used as a key into the dictionary to store the corresponding datum. This means that you can specify the same key multiple times in the key/datum list, and the final dictionary’s value for that key will be the last one given.
这意味着通过以下方式形成 dict
是完全合法的:
d = { 'a': 1, 'b':2, 'b':3 }
然而,我几乎看不出有任何人愿意这样定义它的原因,我通常认为这是一个错误。如果将关键字参数与函数进行比较,则禁止相应的构造。
有什么好的方法可以避免这种情况吗?
最佳答案
此“错误”已被报告、讨论并最终被拒绝 - 参见 https://bugs.python.org/issue16385 .
拒绝者指出的主要原因是
A code generator could depend on being able to write duplicate keys without having to go back and erase previous output.
还有那个
An error is out of the question for compatibility reasons.
关于python - 为什么 `dict_display` 允许重复键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41802298/
我的意思不是因为标准这么说,而是它的基本原理。规范说: If a comma-separated sequence of key/datum pairs is given, they are eval
我是一名优秀的程序员,十分优秀!