How do we compare the elements of two lists in Python?
Answers
Answered by
0
So your lists contains sets as elements.
Loop through two list using nested loops and compare list items (which are sets here ) using equality ( == ) operator .
something like :
for i in a:
for j in b:
if i == j :
#do what you want to do
else:
#other thing you want to do if not equal
Loop through two list using nested loops and compare list items (which are sets here ) using equality ( == ) operator .
something like :
for i in a:
for j in b:
if i == j :
#do what you want to do
else:
#other thing you want to do if not equal
Answered by
0
Hola mate.
Its a Example for u.:
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).
Hope this helps u dude ✌
If helpful Mark it as Brainliest answer ❤️
Similar questions
Art,
6 months ago
Computer Science,
6 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Science,
1 year ago