Question: It is a PYTHON QUESTION! I have no idea how to make a comparison between list and sublist. Please help. A sublist is a list
It is a PYTHON QUESTION! I have no idea how to make a comparison between list and sublist. Please help.
A sublist is a list that makes up part of a larger list. A sublist may be a list containing a single element, multiple elements, or even no elements at all. For example, [1], [2], [3] and [4] are all sublists of [1, 2, 3, 4]. The list [2, 3] is also a sublist of [1, 2, 3, 4], but [2, 4] is not a sublist [1, 2, 3, 4] because the elements 2 and 4 are not adjacent in the longer list. The empty list is a sublist of any list. As a result, [] is a sublist of [1, 2, 3, 4]. A list is a sublist of itself, meaning that [1, 2, 3, 4] is also a sublist of [1, 2, 3, 4]. In this exercise you will create function, isSublist( ), that determines whether or not one list is a sublist of another. Your function should take two lists, larger and smaller, as its only parameters. It should return True if and only if smaller is a sublist of larger. Write main program that demonstrates your function.
As a result, for example while printing
isSublist([1,2,3,4], []), it returns True isSublist([1,2,3,4], [1]), it returns True isSublist([1,2,3,4], [4]), it returns True isSublist([1,2,3,4], [2,3]) it returns True isSublist([1,2,3,4], [2,4]), it returns False isSublist([1,2,3,4], [1,2,3,4]), it returns True
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
