How can I add tuples from two tuple lists to get a new list of results?
For instance:
a = [(1,1),(2,2),(3,3)] b = [(1,1),(2,2),(3,3)]
We want to get
c = [(2,2),(4,4),(6,6)]
I searched google and found many results on how to simply add two lists together using zip, but could not find anything about the two lists of tuples.
use zip twice and understand the list:
zip
In [63]: a = [(1,1),(2,2),(3,3)] In [64]: b = [(1,1),(2,2),(3,3)] In [66]: [tuple(map(sum, zip(x, y))) for x, y in zip(a, b)] Out[66]: [(2, 2), (4, 4), (6, 6)]
>>> a = [(1,1),(2,2),(3,3)] >>> b = [(1,1),(2,2),(3,3)] >>> [(i[0]+j[0], i[1]+j[1]) for i, j in zip(a,b)] [(2, 2), (4, 4), (6, 6)]
Source: https://habr.com/ru/post/943834/More articles:Predict.glm does not predict missing values ββin the answer - rXHR progress events arrive too fast - ajaxMasked inputs using PhoneGap on Android - jquery-mobileHow to check user latency on server in browser using javascript? - javascriptjQuery mobile input blocking does not work - html5A few custom Google Maps markers - javascriptQt Quick vs Graphics View Framework (QGraphicsScene) - qtGet screen resolutions in C # class (without forms / wpf / aps.net / ...) - c #How to upload multiple files using the Zend framework? - phpRepeat the code block a fixed number of times - c ++All Articles