I have 2 lists of dicts:
hah = [{1:[datetime(2014, 6, 26, 13, 7, 27), datetime(2014, 7, 26, 13, 7,27)]},
{2:datetime(2014, 5, 26,13,7,27)}]
dateofstart = [{1:datetime(2013, 6, 26, 13, 7, 27)}, {2:datetime(2013, 6,
26,13,7,27)}]` (just examples).
And I need to create a new list of dicts that contains the same keys and as a value has a difference between dates from the hah and dateofstart.
It should look like this:
[{1:[365, 334]}, {2:[390]}]
When i tried to do it myself i got this code
dif = list()
diff = list()
for start in dateofstart:
for time in hah:
if start.keys() == time.keys():
starttime = start.values()
timeofpay = time.values()
for payments in timeofpay:
dif.append(starttime.pop(0) - payments)
diff.append({str(start.keys()):str(dif)})
And it runs with a following error:
Traceback (most recent call last):
File "/Users/mihailbasmanov/Documents/date.py", line 78, in <module>
dif.append(starttime.pop(0) - payments)
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'list'
Edition:
Managed to do it (almost) by myself. Here is resulted code:
for start in dateofstartbuyer:
for time in hah:
if start.keys() == time.keys():
starttime = start.values()
starttimetime = starttime.pop(0)
timeofpay = time.values()
for payments in timeofpay:
if type(payments) == list:
for wtf in payments:
dif.append(wtf - starttimetime)
else:
dif.append(payments - starttimetime)
key = str(start.keys())
diff.append({key[1:2]:str(dif)})
dif = list()
print(diff)
If you have a suggestion how to make this code more productive your welcome to post your suggestions in the comments or in answers.