在蟒蛇3.X keys(),values()并items()返回意见.现在虽然视图肯定有优势,但它们似乎也会导致一些兼容性问题.例如matplotlib(最终是numpy).作为一个例子这和这对stackexchange问题的答案只是正常工作与Python 2.x的,但在Python 3.4执行他们的时候抛出一个异常.
一个最小的例子是:
import matplotlib.pyplot as plt
d = {1: 2, 2: 10}
plt.scatter(d.keys(), d.values())
Run Code Online (Sandbox Code Playgroud)
哪个TypeError: float() argument must be a string or a number, not 'dict_values'用python 3.4 引发.
虽然对于最小的例子,Exception非常清楚,但是由于同样的问题而出现了这个问题,而且这里的Exception不太清楚:TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' …