On 11/11/2022 19:56, DFS wrote:

Edit: found a solution online:
-----------------------------------------------------------------
x = [(11,1,1),(1,41,2),(9,3,12)]
maxvals = [0]*len(x[0])
for e in x:
     maxvals = [max(w,int(c)) for w,c in zip(maxvals,e)]
print(maxvals)
[11,41,12]
-----------------------------------------------------------------

So now the challenge is making it a one-liner!


 x = [(11,1,1),(1,41,2),(9,3,12)]
 print(functools.reduce( lambda a,b : [max(w,c) for w,c in zip(a,b)],
                x, [0]*len(x[0])))


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to