Here are the instructions (please be patient, this is literally my 1st week trying to write VERY SIMPLE functions in Python). Every example I've found uses things my class hasn't used before.
"Define a function called longest_word(list_of_words), this function takes in a list of
words, i.e. ['apple', 'orange', 'banana'] and returns the the longest word. If there is more than one word tied for the longest, it will return the first.
a. For example, if you called the function as we do in the code below, you should get the output indicated:
word_list = [ 'apple' , 'orange' , 'banana' ]
result = longest_word(word_list)
print(result)"
So I tried this among many, many other failed attempts:
list_of_words = ['antman','spiderman','blackwidow','thor']
word_list_long = []
def longest_word(list_of_words):
for word in list_of_words:
if len(word) > len(word_list_long):
word.append(word_list)
len(word) != len(word_list_long)
return word_list
result = word_list_long
print(result)
And the result is
[], expected output is blackwidow