Question 5 - Past Year - 3 Mark Questions - Chapter 14 - Functions in python
Last updated at April 16, 2024 by Teachoo
Define a function overlapping () that takes two lists and returns true if they have at least one member in common, False otherwise.
Answer:
def
overlapping
(l1,l2):
len1=len(l1)
len2=len(l2)
for i in range(len1):
for j in range(len2):
if l1[i]==l2[j]:
return True
return False
Transcript
Question 5 Define a function overlapping () that takes two lists and returns true if they have at least one member in common, False otherwise.
Defining a function to check if two lists are overlapping
For loop which iterates from 0 to the length of ‘l1’
If at any point the elements in the list overlap, then the function returns true
Taking the length of the 2 lists and assigning it to variables len1 and len2
For loop which iterates from 0 to the length of ‘l2’
If the elements of the 2 lists don’t overlap at any point then the function returns false
Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.
Hi, it looks like you're using AdBlock :(
Displaying ads are our only source of revenue. To help Teachoo create more content, and view the ad-free version of Teachooo... please purchase Teachoo Black subscription.
Please login to view more pages. It's free :)
Teachoo gives you a better experience when you're logged in. Please login :)
Solve all your doubts with Teachoo Black!
Teachoo answers all your questions if you are a Black user!