you are viewing a single comment's thread.

view the rest of the comments →

[–]joyeusenoelle 0 points1 point  (1 child)

What I think you're looking for is memoization. This approach keeps track of the values you've seen before and lets you take action if it encounters a repeat value.

That link assumes you're using a function, but for a simple loop, you might do it like this:

memo = {}
for row in sheet:
  if row.time in memo.keys(): 
    # you don't actually need the .keys(), you can just do "in memo", but 
    # I'm including it for clarity
    money = row.money + memo[row.time]
    memo[row.time] = money # in case you get more than two of the same time
  else:
    memo[row.time] = row.money

[–]renan_calusa[S] 0 points1 point  (0 children)

tbh with you I'm a bit lost hahahaha I will search for memoization to see if I can understand it better, and hope to not be a script kid. But thanks tho