Help in this Python question.! | Sololearn: Learn to code for FREE!
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))

20th Oct 2021, 3:08 PM
Saurav Singh
Saurav Singh - avatar
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)
20th Oct 2021, 6:07 PM
Lothar
Lothar - avatar
+ 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))
20th Oct 2021, 3:53 PM
ubai
ubai - avatar
+ 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.
20th Oct 2021, 3:22 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
1)print(len(set(a+b)) != len(a+b)) 2)print(bool(set(a)&set(b)))
22nd Oct 2021, 3:24 AM
Prabhas Koya
+ 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))
20th Oct 2021, 3:13 PM
Oma Falk
Oma Falk - avatar