Check if two lists have at-least one element common | Sololearn: Learn to code for FREE!

0

# Check if two lists have at-least one element common

Example: Input : a = [1, 8, 2, 4, 5] b = [2, 6, 7, 8, 9] Output : True Input : a=[1, 2, 3, 4, 5] b=[6, 7, 8, 9] Output : False

10/31/2021 8:51:41 AM

Shubham Lokhande

+6

Shubham Lokhande This looks interesting, do you have a concept to show us, or do you just want us to do it for you?

+6

Muhammad Galhoum you are showing a really nice code to help someone solving a task. we all appreciate this very much!  (this is my personal statement - but it is not to criticize someone !!) but there is an issue by giving a ready solution, when the op has not done and shown his attempt first. as a part of the community i believe that learning by doing is more helpful, than just using a shared solution. we should act more as a mentor.  it is a very successful way when we are giving hints and help, so that the op is able to solve his task by himself. it would be great if you are going to help us to keep sololearn what it is: ▪︎a unique place to learn (we are a "self" learning platform!) ▪︎an absolutely great community that is willing to help other people  ▪︎a great resource of people which has an unbelievable knowledge in coding and a long lasting experience ▪︎a place to meet people and to discuss with them all the possible points of view thanks for your understanding

+4

print(True if set(a) & set(b) else False)

+2

U can use for loop on one of them and check if any element exists in the other list OR u can use function a =[1,8,2,4,5] b=[2,6,7,8,9] count = 0 for ele in a: if ele in b: count += 1 continue if count >= 1: print ("True") print ("False")

-2

It's just a random question you can try to solve it