Write a function called sublist. The function takes 2 lists as parameters, and returns True if the items in the first list appear in the same order somewhere in the second list (and False if they don't)
Here are some examples:
>>> sublist([2, 3], [1, 2, 3, 4, 5]) True
>>> sublist([1, 3], [1, 2, 3, 4, 5]) False
>>> sublist([1, 2, 3], [1, 2, 1, 2, 3, 4]) True
Here's what I have so far:
def sublist(list1,list2):
for i in range(len(list2)):
if list2[i] != list1[i]:
return False
return True
output:
>>> sublist([2,3],[1,2,3,4,5])
False
>>> sublist([1,3],[1,2,3,4,5])
True
>>> sublist([1,2,3],[1,2,1,2,3,4])
True
I know that's not entirely right and I know I'm going to have to use [ : ] to extract a portion of a string or a list but I have no idea where to start. Any help would be great, thank you.