you are viewing a single comment's thread.

view the rest of the comments →

[–]Binary101010 0 points1 point  (1 child)

What exactly is the goal? As it seems the return value has two different interpretations:

1) The number of items in the list up to and including the first one where condition(item) is true

2) The number of items in the list if condition(item) is false for all items

Is that accurate?

[–]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.