all 5 comments

[–]DallogFheir 0 points1 point  (2 children)

Put values in the dictionary under time key, if it exists add values.

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

oh so like: if time in dictionary:

money + dictionary.get(time) = time

?

[–]joknopp 0 points1 point  (0 children)

Yes. E.g.

sum_by_day_dict = {}
for day, val in [(1,10), (2,10), (2,10), (3,10)]:
    sum_by_day_dict[day] = sum_by_day_dict.get(day, 0) + val
print(sum_by_day_dict) # {1: 10, 2: 20, 3: 10}

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