使用unicode dict键令人惊讶的行为

时间:2018-05-02 02:17:08

标签: python dictionary unicode ipython

考虑以下代码:

In [1]: a = {'ϵ': 1}

In [2]: b = dict(ϵ=1)

In [3]: a == b
Out[3]: False

In [4]: print(a, b)
{'ϵ': 1} {'ε': 1}

我很惊讶地发现a不等于b。尽管有类似的定义(我在我的IPython环境中输入\epsilon + tab),但生成的dicts似乎对epsilon使用不同的Unicode符号。

我想知道为什么会发生这种情况,如果在这种情况下有一种首选的方法来处理Unicode密钥。

0 个答案:

没有答案