Is it reasonable to use None as a dictionary key in Python?

前端 未结 6 2221
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 20:15

None seems to work as a dictionary key, but I am wondering if that will just lead to trouble later. For example, this works:

>>> x={\'a\':1, \'b\':2, N         


        
6条回答
  •  星月不相逢
    2021-02-06 21:02

    It seems to me, the larger, later problem is this. If your process is creating pairs and some pairs have a "None" key, then it will overwrite all the previous None pairs. Your dictionary will silently throw out values because you had duplicate None keys. No?

提交回复
热议问题