- Use
min(list)
to get the minimum value across a list - use
max(list)
to get maximum value across a list
data = [
[30, 30, 20],
[10, 5, 10],
[20, 20, 30],
[8, 20, 10]
]
new_list = []
for i in range(4):
if i < 2:
new_list.append(min(data[i]))
else:
new_list.append(max(data[i]))
print(new_list)
# Output
# [20, 5, 30, 20]
I know using a map and lambda can be less verbose and cool looking. But as the author of the question is a python beginner, I am using a for loop and the append method.
9
solved How to get the min value for the first two columns and the max value for the next two in a list of 4 columns in python? [closed]