In: Computer Science
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Implement the program as follows:
Program:
Note: Please double-check the indentation using the screenshot provided as a reference
def is_string_in_list(list_of_string, str_val): # define the function is_string_in_list() that accepts a list of string and a string value
is_present = False # initialize is_present t0 False
if str_val in list_of_string: # Use 'in' operator to check if the list contains str_val
is_present = True # Update is_present to True if str_val is present in list
return is_present # return is_present
list1 = ['eggs', 'milk', 'bananas'] # create a list, list1
print('list1', list1)
print(is_string_in_list(list1, 'pumpkin')) # call is_string_in_list() to check if the list contains a particular string value
list2 = ['eggs', 'milk', 'bananas', 'pumpkin']
print('list2', list2)
print(is_string_in_list(list2, 'pumpkin'))
Screenshot:
Output:
Please don't forget to give a Thumbs Up.