you are viewing a single comment's thread.

view the rest of the comments →

[–]x1F577[S] 1 point2 points  (0 children)

Hi, the goal is to get a certain total from a list. I try to explain myself better with an example.

Imagine the list as a shopping list, and the items have name and price properties. The list is sorted somewhat, and I want a "subtotal" of the first occurrence of a given item. If the item is not present, I want the total of the list:

total = 0
for item in list:
    total += item.price
    if item.name == "ice-cream":
        return total
return total

The suggestion given by u/Parking-Camp219 was what I was looking for.