def sublist(slist, blist):
m = 0
is_a_sublist = False
for n in range(0, len(blist)):
while (n < len(blist) and m < len(blist)) and is_a_sublist == False:
spliced_list = blist[n:m]
if spliced_list == slist:
is_a_sublist = True
else:
m += 1
return is_a_sublist
def main():
test_list = ["a",9,1,3.14,2]
original_list = ["a",1,"a",9,1,3.14,2]
is_a_sublist = sublist(test_list,original_list)
if is_a_sublist == True:
print("It is a sublist!")
else:
print("It ain't a sublist!")
main()
The code I wrote above is to check if a given list is a "sublist" of a larger list. So, if a large list is [3,3,10,4,9], and the given list is [3,10,4], then it is a sublist so it must return True. But what's wrong with my code? When I run it, output is "It ain't a sublist" even though it is (function returns False). I only want to use loops, no built-in functions.