Issue
for example I have the following list
lst = [['1', '2', '3'], ['4', '5', '6'],['7', '8', '9']]
I want to find the average of 1+4+7, 2+5+8 and 3+6+9 Any idea on how to create such a function?
Solution
You can use a simple list comprehension:
lst = [['1', '2', '3'], ['4', '5', '6'],['7', '8', '9']]
from statistics import mean
out = [mean(map(int, x)) for x in zip(*lst)]
Output: [4, 5, 6]
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.