Sourcery refactoring id:
Replaces summed values created with
for loops with
total = 0 for hat in hats: total += hat.price
total = sum(hat.price for hat in hats)
Much of programming is about adding up lists of things, and Python has the built-in
to help with this.
This is much shorter, which is a definite bonus. The code also now explicitly tells you what it is trying to do - sum the price of all the hats.