CodyKochmann
1/20/2017 - 7:47 PM

returns the index of a list if it is a sublist of another list in python

returns the index of a list if it is a sublist of another list in python

def find_sublist(l1,l2,depth=0):
    """ returns the index of a list in another list 
        by: Cody Kochmann """
    if not len(l1) or not len(l2): return -1
    return depth if l2[:len(l1)] == l1 else find_sublist(l1, l2[1:], depth+1)