user2918984
user2918984

Reputation: 121

max() function, getting the max tuple

SO i wand to use max() in order to check 3 tuple in the form of (int, str, str), i want to get the max value of cell 1 out of the 3, but i want to add different ints. exmpale:

    tup_1 = 5, 'adasd', 'dadas'
    tup_2 = 4, 'adasda', 'dadad'
    tup_3 = 3, 'adasds', 'asdasda'
    gap = -2
    score = 2

    max(tup_1[0] + score, tup_2[0] + gap, tup_3[0] + gap)

i want to get back the tuple with the max value of the first cell, again i wan the tuple not the int, any ideas?

Upvotes: 1

Views: 131

Answers (1)

martineau
martineau

Reputation: 123453

tup_1 = 5, 'adasd', 'dadas'
tup_2 = 4, 'adasda', 'dadad'
tup_3 = 3, 'adasds', 'asdasda'
gap = -2
score = 2

print(max((tup_1[0] + score, tup_1),
          (tup_2[0] + gap, tup_2),
          (tup_3[0] + gap, tup_3))[1])

Upvotes: 1

Related Questions