check if elements from one list occur in another list with recursions closed

This isn’t exactly recursive, but simpler.

set(firstLst).issubset(set(secondLst))

For a recursive answer,

def firstInSecond(lst1,lst2):
    if len(lst1) == 0:
       return True
    if lst1[0] in lst2:
       return firstInSecond(lst1[1:], lst2)
    else:
       return False

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top