New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Help in this Python question.!
Write a Python function that takes two lists and returns True if they have at least one common member. INPUT [1,2,3,4,5] [5,6,7,8,9] OUTPUT True CODE a=input() b=input() result=0 def data(a,b): for x in a: for y in b: if x==y: result = True return result else: result = None return result print(data(a,b))
5 Answers
+ 7
lst1 = [1,2,3,4,5]
lst2 = [5,6,7,8,9]
print(True) if any(i in lst2 for i in lst1) else print(False)
+ 4
a=[1,2,3,4,5]
b=[6,6,7,8,5]
data = lambda x,y:bool([i for i in x if i in y])
print(data(a,b))
+ 2
Saurav Singh , that's not the way to read a list => a = input () or b = input (). This way you'll get a single value as string. The description isn't clear => you'll get all elements in single line or every element is given in separate line.
+ 2
1)print(len(set(a+b)) != len(a+b))
2)print(bool(set(a)&set(b)))
+ 1
Help in this Python question.!
Write a Python function that takes two lists and returns True if they have at least one common member.
INPUT
[1,2,3,4,5]
[5,6,7,8,9]
OUTPUT
True
CODE
a=input()
b=input()
result=0
def data(a,b):
for x in a:
for y in b:
if x==y:
result = True
return result
return False
print(data(a,b))