I have the following dictonary:
inventory = {'apple':(3, 133), 'banana':(9, 407), 'pear':(17, 205), 'orange':(1, 91)}
I would like to find key, value pair according to max value of the second element in the tuple so in this case it should return: banana':(9, 407) I know I can get this result using lambda:
key_max = max(inventory.keys(), key=(lambda k: inventory[k][1]))
print key_max, inventory[key_max]
However I try to receive same result using itemgetter() method as I read it is faster but I can only get data according to the value of first element of the tuple:
from operator import itemgetter
print max(inventory.iteritems(), key = itemgetter(1))
Is there a way I could get same result using itemgetter() method?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)