0

Example:

input=[(10,1),(2,3),(6,2)]
output= 3 

(since the maximum of the 2nd dimension is 3, 3 is returned)

3 Answers 3

1

You can use max with key parameter.

input=[(10,1),(2,3),(6,2)]
output=max(input,key=lambda x:x[1])[1]
# 3

You can use itemgetter(If you don't prefer using lambda)

from operator import itemgetter
output=max(input,key=itemgetter(1))[1]
# 3
Sign up to request clarification or add additional context in comments.

Comments

1

You can use numpy to do exactly this

import numpy as np
a = np.array(input)
print(a[: , 1].max())

1 Comment

Ohh.. I didn`t understand that this is the desired output. Fixed it.
0

I don't know that function there are or no. But look at this:

my_items = [(10,1),(2,3),(6,2)]

my_items.sort(key=lambda e: e[0])

print (my_items[0])

execute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.