The Question is: You are to write a function, called isSublist(), which takes two arguments (list, sublist) and returns 1 if sublist is a sub-list of list, and 0 otherwise.
So i have my code however I get True when the sublist is not in list. Any suggestions on fixing this please?
def isSublist(list, sublist):
for i in range(len(list)-(len(sublist))+1):
return True
if sublist==list[i:i+(len(sublist))]:
return False
sample input:
list= (0,1,2,3,4,5,6,7,8,9)
isSublist(list, [1,2,3])
output:
True
[1,2,3] in [[1,2,3], [5,6,7]], or do you mean[1,2,3] in [1,2,3,4,5,6]? - Steinar Lima[1, 2, 3]and[2, 3, 1]? - Steinar Limasublist = [2, 1]? And what iflist = [1, 1, 2, 2, 3]andsublist = [1, 2, 3]? - Steinar Lima