Python: what is the fastest / most elegant way to see if every number in two arrays is the same?
ie, compare:
1,-1,1
to
1.0,-1, 1
should be the same
print("the input and the output are " + ( (input == calc_out) ? "the sam开发者_StackOverflow社区e" : "not the same"))
but it give a lexical error =\
The docs indicate various ways you can compare sequences and other types:
(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)
So for your example:
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
==
found it... Python does Ternary weird:
print("the input and the output are " + ( "the same" if (input == calc_out) else "not the same"))
精彩评论