Is there a way to sum a list based on another list?

This might help get you started on accomplishing your ultimate goal:

Date = ['01-01-2019', '02-01-2019', '02-01-2019']

Time = ['07:00:00', '06:00:00','02:00:00']

import datetime

data = zip(Date, Time)

dates = []

for d in data:
    dt = datetime.datetime.strptime("{}, {}".format(*d), "%m-%d-%Y, %H:%M:%S")
    dates.append(dt)

totals = {}
for d in dates:
    if d.date() not in totals: totals[d.date()] = d.hour
    else: totals[d.date()] += d.hour

for date, time in totals.items():
    if time >= 8:
        # do something
        print('do something:', date)
    else:
        print('do something else.')

Leave a Comment