Mar-11-2019, 08:26 PM
List = [[0,1,2],[4,5,6,7],[7,8,9,10]] def ReplacewithMax (l, count = 0, L = None): if count == 0: L = [] K = [] for i in l[count]: K.append(max(l[count])) L.append(K) count += 1 return ReplacewithMax(l,count,L) if count < len(l): K = [] for i in l[count]: K.append(max(l[count])) L.append(K) count += 1 return ReplacewithMax(l,count,L) if count == len(l): return L K = ReplacewithMax(List) print (K)I have a nested list. In the second level, I want to replace theirs item with the maximum value in each list. The code I post achieved the goal. But I'm seeking for a simpler way to do that.
Thanks!