Python:用什么最快/最优雅的方法来判断两个数组中的每个数字是否相同?
例如,比较:Python:用什么最快/最优雅的方法来判断两个数组中的每个数字是否相同?,python,Python,例如,比较: 1,-1,1 到 应该是一样的 print("the input and the output are " + ( (input == calc_out) ? "the same" : "not the same")) 但是它给出了一个词法错误=\==文档表明您可以比较序列和其他类型: (1, 2, 3) < (1, 2, 4) [1, 2, 3] < [1, 2, 4] 'ABC' < 'C' <
1,-1,1
到
应该是一样的
print("the input and the output are " + ( (input == calc_out) ? "the same" : "not the same"))
但是它给出了一个词法错误=\
==
文档表明您可以比较序列和其他类型:
(1, 2, 3) < (1, 2, 4)
[1, 2, 3] < [1, 2, 4]
'ABC' < 'C' < 'Pascal' < 'Python'
(1, 2, 3, 4) < (1, 2, 4)
(1, 2) < (1, 2, -1)
(1, 2, 3) == (1.0, 2.0, 3.0)
(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
找到了。。。Python做了以下工作:
print("the input and the output are " + ( "the same" if (input == calc_out) else "not the same"))
您是否真的尝试过使用
==
?问题不够具体-您希望输出的内容是什么?如果您发布代码以获得最佳解决方案,您可能会在几分钟内收到相关答案。1,2,3
与3,2,1
相同吗?如果是这样,那就完全不同了。不。。。就在我的例子中,可能有小数。。。但是它们的顺序是一样的=\
C:\Users\jon>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> [1,-1,1] == [1.0,-1,1]
True
print("the input and the output are " + ( "the same" if (input == calc_out) else "not the same"))