Lesson 4 of 4
Lists
A list holds several values in order, inside square brackets:
Lists can grow with .append():
Looping over a list
for works directly on lists, and if lets you choose what to do with each item:
Exercise: Longest word
Write longest_word(words) that returns the longest string in the list. If several are tied, return the first one.
Your turn!
Write your code in and press Submit answer.
- print(longest_word(["ale", "mushrooms", "pie"])) → mushrooms
- print(longest_word(["one", "two", "six"])) → one
- plus 2 hidden checks