0

I have the following list:

[[733.16584917887963, 123620000.0, 32111000.0, 301.0],
 [732.27472276611104, 123620001.0, 32111000.0, 302.3], 
 [731.39029416733558, 123620002.0, 32111000.0, 303.3], 
 [730.49893696170341, 123620003.0, 32111000.0, 303.9], 
 [729.61188100398681, 123620004.0, 32111000.0, 304.2]]

I want to have the array of this list that has the minimum in the first element of this array.

The minimum value is:

729.61188100398681

And I want to have as output:

[729.61188100398681, 123620004.0, 32111000.0, 304.2]
Stefan
  • 1,383
  • 2
  • 15
  • 25

2 Answers2

2

Sort the list and take out the first sublist:

lista = [[733.16584917887963, 123620000.0, 32111000.0, 301.0],
 [732.27472276611104, 123620001.0, 32111000.0, 302.3], 
 [731.39029416733558, 123620002.0, 32111000.0, 303.3], 
 [730.49893696170341, 123620003.0, 32111000.0, 303.9], 
 [729.61188100398681, 123620004.0, 32111000.0, 304.2]]

print(sorted(lista)[0]) # [729.6118810039868, 123620004.0, 32111000.0, 304.2]
bhansa
  • 7,282
  • 3
  • 30
  • 55
2

You can use sorted and lambda function to get the result just like this:

my_list = [[733.16584917887963, 123620000.0, 32111000.0, 301.0],
[732.27472276611104, 123620001.0, 32111000.0, 302.3], 
[731.39029416733558, 123620002.0, 32111000.0, 303.3], 
[730.49893696170341, 123620003.0, 32111000.0, 303.9], 
[729.61188100398681, 123620004.0, 32111000.0, 304.2]]

sorted_lst = sorted(my_list,key=lambda elem:elem[0])

print sorted_lst[0]
#Output : [729.6118810039868, 123620004.0, 32111000.0, 304.2]

Similarly you can change the key to any of the elements as per your choice.

Gambit1614
  • 8,547
  • 1
  • 25
  • 51