Refactor Exercise 5 using lists instead of a dictionary