I am new to python. Using it with grasshopper. I have 5 lists, each actually with 8760 items for which i have found max values at each index "but I also need to know which list the value came from at any given index."
I would put a simple example to explain myself better. For 2 lists A = [5,10,15,20,25] B = [4,9,16,19,26]
Max value per index = [5,10,16,20,26]
What I want is something like Max value per index = [5(A), 10(A), 16(B), 20(A), 26(B)]
Or something along the line that can relate. I am not sure whether its possible.
I would really appreciate the help. Thank you.
This can be adapted to N lists.
[(max(a),a.index(max(a))) for a in list(zip(A,B))]
The .index(max(a))
gets the index at which the max(a)
occurs.
The output for your example is
[(5, 0), (10, 0), (16, 1), (20, 0), (26, 1)]
Of course, if both A
and B
share the same value, then the index will be the first one found, A
.
See https://docs.python.org/3.3/library/functions.html for description of very useful zip
built-in function.