Write a function that takes two integer lists (not necessarily sorted) and returns true precisely when the first list is a sublist of the second.
The first list may appear anywhere within the second, but its elements must appear contiguously.
HINT: You should define and test a helper function that you can use in sublist.

Respuesta :

Answer:

The function written in Python is as follows:

def checksublist(lista,listb):

     if(all(elem in lista for elem in listb)):

           print("The first list is a sub list of the second list.")  

     else:

           print("The first list is not a sub list of the second list.")

Explanation:

This line defines the function

def checksublist(lista,listb):

The following if condition checks if list1 is a subset of list2

     if(all(elem in lista for elem in listb)):

           print("The first list is a sub list of the second list.")  

The following else statement is executed if the above if statement is not true

     else:

           print("The first list is not a sub list of the second list.")

The function that takes two integer lists (not necessarily sorted) and returns true precisely when the first list is a sub list of the second is as follows:

def check_sublist(x, y):

  if(set(x).issubset(set(y))):

     return "The first list is a sublist of the second"

  else:

     return "The first list is not a sublist of the second"

print(check_sublist([2, 3, 5], [1, 2, 3, 4, 5, 6, 7]))

The code is written is python.

Code explanation:

  • A function is declared called check_sublist. The function accept two parameters namely x and y.
  • if the parameter x is a subset of y then the it will return  "The first list is a sublist of the second"
  • Else it will return  "The first list is not a sublist of the second"
  • Finally, we use the print statement to call our function with the required parameter.

learn more on python code here; https://brainly.com/question/25797503?referrer=searchResults

Ver imagen vintechnology