Abhishek Abhishek
Abhishek Abhishek

Reputation: 87

find maximum values per column inside nested list except the first one

I have to find maximum elements per column except the first column inside the nested list I tried using that but that didn't worked

v=[['a',1,10,3],['b',2,3,11],['c',3,4,5]]

answer =v[0]
for current in v[1:]:
    answer = [max(x, y) for x, y in zip(answer[0][1:], current[1:])]
print(answer)

it should return [3,10,11]

Upvotes: 1

Views: 28

Answers (1)

Rhys Pang
Rhys Pang

Reputation: 223

you can try this

ans = [max(i) for i in list(zip(*v))[1:]]

Upvotes: 1

Related Questions