Reputation: 79
list_a = [[0, 3], [2, 4], [25, 17]]
I want to iterate over list_a
and find out the min
and the max
of all elements on index [1]
for every single element of list_a
.
My first shot was
min_list = min(list_a[0:][1])
max_list = max(list_a[0:][1])
but that was wrong. What is the correct way?
Upvotes: 0
Views: 313
Reputation: 628
You can use list comprehension:
min_list = min([e[1] for e in list_a])
max_list = max([e[1] for e in list_a])
You can actually generalize this for any i-th
element you like:
i = 1
min_list = min([e[i] for e in list_a])
Upvotes: 1