平均值:
>>> data = [[1, 2, 3], [1, 3, 4], [2, 4, 5]]
>>> from __future__ import division
>>> [sum(e)/len(e) for e in zip(*data)]
[1.3333333333333333, 3.0, 4.0]
和:
>>> data = [[1, 2, 3], [1, 3, 4], [2, 4, 5]]
>>> [sum(e) for e in zip(*data)]
[4, 9, 12]
returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments … write the function call with the *-operator to unpack the arguments out of a list or tuple.
>>> data
[[1, 2, 3], [1, 3, 4], [2, 4, 5]]
>>> zip(*data)
[(1, 1, 2), (2, 3, 4), (3, 4, 5)]