+ 4
How can two objects from different lists be compared?
I tried it by using == (if list1[0]==list2[0]) but it gives out syntax error :(
4 ответов
+ 2
"""I don't know how you did it, since you have not linked your code here but here is mine"""
lst1 = [1,2]
lst2 = [2,1]
if lst1[1]==lst2[0]:
print(True)
"""and it worked perfectly fine, I think you have missed the colon after the if statement or may be it is because of that equal sign before the if statement"""
+ 2
yeah.... but if you want messy code why use python ...
Go for java or cpp
lol
0
Thank you Indeed missed that colon :)
0
and found some more interesting stuff because of it:
quote"
Not the most efficient one, but by far the most obvious way to do it is:
>>> a = [1, 2, 3, 4, 5] >>> b = [9, 8, 7, 6, 5] >>> set(a) & set(b) {5}
if order is significant you can do it with list comprehensions like this:
>>> [i for i, j in zip(a, b) if i == j] [5]
(only works for equal-sized lists, which order-significance implies).
answered Sep 7 '09 at 11:10

SilentGhost
https://stackoverflow.com/a/1388836