2

I have dict like follows:

a = {'abc':[0,1,2], 'def':[0,1,2,3,4], 'ghi':[0,1,2,3,4,5]}

Want to get the key based on the max length of the array contains. As in here, out put would be 'ghi'. Anybody how to do it. I have tried:

lambda x: max(len(x[1])), a.items() but it doesn't solve the purpose. Can anyone tell what should I do?

martineau
  • 119,623
  • 25
  • 170
  • 301
abhi1610
  • 721
  • 13
  • 28

2 Answers2

5

Try:

max(a, key=lambda x: len(a[x]))

Aaron_ab
  • 3,450
  • 3
  • 28
  • 42
-1

try this:

a = {'abc':[0,1,2], 'def':[0,1,2,3,4], 'ghi':[0,1,2,3,4,5]}

print(list(a.keys())[list(a.values()).index(max(a.values()))])
Selaron
  • 6,105
  • 4
  • 31
  • 39
Manoj Kumar
  • 176
  • 7