Original Question here
I want to sum the [qty] based on [pid][dbid][eid][sid].
this code works on v3.6.4 but when i migrate to v3.4, then i got an error message:
new_d = [ [{'pid': 146, 'dbid': 1, 'eid': 6212, 'qty': 10, 'sid': 6}, {'pid': 146, 'dbid': 1, 'eid': 6212, 'qty': 20, 'sid': 6}],
[{'pid': 232, 'dbid': 1, 'eid': 6212, 'qty': 1, 'sid': 56}, {'pid': 232, 'dbid': 1, 'eid': 6212, 'qty': 1, 'sid': 56}],
[{'pid': 146, 'dbid': 1, 'eid': 6212, 'qty': 100, 'sid': 56}, {'pid': 146, 'dbid': 1, 'eid': 6212, 'qty': 100, 'sid': 56}]]
final_result = [{**i[0], **{'qty':sum(b['qty'] for b in i)}} for i in new_d]
^
SyntaxError: invalid syntax
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…