I would like to find the largest element in a list and zero out the rest of the elements. I am not looking for the index of the element, just what the example shows:
So I would go from:
Example:
a = [1,2,20,5,99,70,35]
To
b = [0,0,0,0,1,0,0]
However, what if I had a list of lists, and I want to go from:
c = [ [33,6,3],[10,50,20],[4,9,77] ]
To
d = [ [1,0,0],[0,1,0],[0,0,1] ]
new_a = [] #create a new empty list
a = [ [33,6,3],[10,50,20],[4,9,77] ] # the list I will loop through
for list in a: # this will go through the lists inside the list "a"
biggest = max(list) # this will find the max elements in lists
new_a.append([1 if i==biggest else 0 for i in list]) #append
print(new_a)
Answer: [ [1,0,0],[0,1,0],[0,0,1] ]