Question

Write a Python function that takes two parameters: the first a list of strings and the...

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.

Homework Answers

Answer #1

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"))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python function that takes two parameters: the first a list of strings and the...
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.
Write a Python function that takes two parameters: the first a list of strings and the...
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.
Write a Python function that takes two parameters: the first a list strings and the second...
Write a Python function that takes two parameters: the first a list 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.
This is an intro to Python question: #Write a function called linear() that takes two parameters...
This is an intro to Python question: #Write a function called linear() that takes two parameters #- a list of strings and a string. Write this function so #that it returns the first index at which the string is #found within the list if the string is found, or False if #it is not found. You do not need to worry about searching #for the search string inside the individual strings within #the list: for example, linear(["bobby", "fred"], "bob") #should...
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
asap python: Write a function called fileCaseSwap that takes 2 filenames (strings) as input parameters. The...
asap python: Write a function called fileCaseSwap that takes 2 filenames (strings) as input parameters. The function should: Open the first file for reading Open the second file for writitng Read the first file Swap the case (swapcase) of every character in the file Write the replaced text to the second file. test call: fileCaseSwap("emma-short.txt", "emma-short-swap.txt") fileCaseSwap("emma.txt", "emma-swap.txt") """ """ The first 3 lines of the emma-short-swap.txt file should be emma bY jANE aUSTEN
Python #Write a function called are_anagrams. The function should #have two parameters, a pair of strings....
Python #Write a function called are_anagrams. The function should #have two parameters, a pair of strings. The function should #return True if the strings are anagrams of one another, #False if they are not. # #Two strings are considered anagrams if they have only the #same letters, as well as the same count of each letter. For #this problem, you should ignore spaces and capitalization. # #So, for us: "Elvis" and "Lives" would be considered #anagrams. So would "Eleven plus...
Use python def a function that takes in a list of passwords (as strings), a password...
Use python def a function that takes in a list of passwords (as strings), a password that needs to be checked (as a string), and an integer that represents the number of repetitions. If the given password occurs given number of times, return True, else return False. eg. >>> repeats(["ma48", "ma28", "ma48"], "ma48", 2) True >>> repeats(["ma48", "ma28", "ma48"], "ma48", 3) False >>> repeats(["ma48", "ma28", "ma48", "ma28", "ma48"], "ma38", 2) False >>> repeats(["ma48", "ma28", "ma48", "ma38"], "ma48", 1) False
Write a Python function called sumNxN with three parameters. The first parameter is a nested list...
Write a Python function called sumNxN with three parameters. The first parameter is a nested list (matrix) representing a matrix of size N x N. The second parameter is the integer N, and the third is a list of N zeros. Modify the list of zeros so that each entry is the sum of the corresponding column. There is no return. Note: You may assume the sizes provided are all correct.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT