Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python coding list matrix help: def return_lengths(my_list_of_string): return a new list: Finish this function which takes a list of strings and returns a list
Python coding list matrix help:
def return_lengths(my_list_of_string): """ return a new list: Finish this function which takes a list of strings and returns a list of integers as the length for each string. For example, for ['how', 'are', 'you'] as the parameter, the return value of this function should be [3, 3, 3] Hint: you can use the code below to create a new, emtpy string: my_new_string = [] """
# test my_string_list1 = ['python', 'hello', '131'] print(return_lengths(my_string_list1)) print("--"*10)
def remove_ALL_cat(my_list): """ remove all the word "cat" from a list -- another solution: Finish this function which takes a list and remove all the "cat" in this list. For example, if the parameter my_list is ["cat", "dog", "tiger", "panther", "cat"], after running this function, the list will become: ["dog", "tiger", "panther"] This function does not have any explicit return value. Hint: use count() to control your loop. """
# test cats_and_birds = ['cat','cat','bird','cat','bird'] remove_ALL_cat(cats_and_birds) print(cats_and_birds) # ['bird', 'bird'] dogs = ['corgi','lab','grayhound'] remove_ALL_cat(dogs) print(dogs) # ['corgi', 'lab', 'grayhound']
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started