i got the following problem. I need to read x number of text files and get the sum of every third list. example would be
file 1
[1.0, 2.0, 3.0]
[3.1, 2.1, 2.1]
[3.4, 3.4, 4.4]
file 2
[1.0, 2.0, 3.0]
[3.1, 2.1, 2.1]
[3.4, 3.4, 4.4]
result:
[2.0, 4.0, 6.0]
[6.2, 4.2, 4.2]
[6.8, 6.8, 8.8]
question is how to get the matching lists to sum?
i know i can use ZIP to get sum of lists and i get the files opened, and read by line and stored into lists, but im not sure how to target the right ones to sum.
if the case was only for 2, i could check with an if condition if the counter is even or odd, but how to handle it when there are 3 cases? does python have a solution built in there? the solution also has to be scalable to an x amount of files containing 3 lists. This also means i cant just make a list of cases sadly.
Thanks!
Aucun commentaire:
Enregistrer un commentaire