本文介绍了将具有相同散列的两个键放入dict的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 c  c 和 c>工作正常,但是比较十进制和复合不。因为比较 one_decimal == one_complex 将始终返回 False ,因为它们的类型,他们都可以生活在同一个字典中Python 2.7。

The short answer to your question is probably that the implementation of the complex type is a bit incomplete in the Python library as of 2.7. As @wim points out, comparing int and complex using == works fine, but comparing Decimal and complex does not. Since comparing one_decimal == one_complex will always return False because of their types, they can both live in the same dictionary in Python 2.7.

此问题已在Python 3中修复。我在3.5中进行实验,其中 one_decimal 和 one_complex 相等。运行相同的代码段后,字典包含 one_complex 的值 one_decimal (如第一个键,最后一个值)。

This issue has been fixed in Python 3. I am experimenting in 3.5, where one_decimal and one_complex are equal. After running the same snippet, the dictionary contains the value for one_complex under the key one_decimal, as expected (first key, last value).

这是Py2.7的复杂的类型。修正于Py3。

It's a bug in Py2.7's complex type. Fixed in Py3.

这篇关于将具有相同散列的两个键放入dict的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:23
查看更多