Answer the question
In order to leave comments, you need to log in
How to perform a comparison?
Guys tell me.
There is such a list: [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
How to correctly compare 7 with 1, 5 with 2, and so on. (any numbers can be)
Something like in Chinese, if:
a = [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
if a[0][0] != a[0][1]:
print ("Не равны")
else:
print ("Равны")
if a[1][0] != a[1][1]:
print ("Не равны")
else:
print ("Равны")
Answer the question
In order to leave comments, you need to log in
a = [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
for a0, a1 in a:
print('равны' if a0==a1 else 'не равны')
>>> lst = [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
>>> [a == b for a, b in lst]
[False, False, False, True]
>>>
for pair in a: - and then extract elements from the tuple and compare.
Option 1
a = [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
[print('равны') for t in a if t[0] == t[1] else print('не равны')]
a = [('7', '1'), ('5', '2'), ('8', '3'), ('4', '4')]
for t in a: print('равны' if t[0] == t[1] else 'не равны')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question