I have this piece of python code below.
def m(list):
v = list[0]
for e in list:
if v < e:
v = e
return v
values = [[3, 4,
Another way to write that code is like this, just for learning purposes:
def max_nest_list(lst):
max_numbers = []
for sub_list in lst:
max_num = sub_list[0]
for num in sub_list[1:]:
if num > max_num:
max_num = num
max_numbers.append(max_num)
return max_numbers
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for item in max_nest_list(values):
print(item, end = " ")
#Output
5 33
Or even more concise:
def max_nest_list2(lst):
return [max(i) for i in lst]
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for item in max_nest_list(values):
print(item, end = " ")