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.
def isStringPresent(lst,string):
i=0
while i<len(lst):
if lst[i]==string:
return True
i=i+1
return False
print(isStringPresent(["eggs","milk","bananas"],"pumpkin"))
print(isStringPresent(["eggs","milk","pumpkin"],"pumpkin"))
Get Answers For Free
Most questions answered within 1 hours.