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

31st Oct 2021, 8:51 AM
Shubham Lokhande
Shubham Lokhande - avatar
5 Réponses
+ 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?
31st Oct 2021, 8:55 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
31st Oct 2021, 9:20 AM
Lothar
Lothar - avatar
+ 4
print(True if set(a) & set(b) else False)
31st Oct 2021, 9:19 AM
Simba
Simba - avatar
+ 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")
31st Oct 2021, 9:07 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
- 1
It's just a random question you can try to solve it
31st Oct 2021, 9:07 AM
Shubham Lokhande
Shubham Lokhande - avatar