-1

I have the following code with some of the output. Is there a way to use python to get the largest value from L or g?

When I try using L=max((g[1])) it gives this error;

TypeError: 'int' object is not iterable.

CODE:

for key, value in G.items():
     
     g=(key, len([item for item in value if item]))
     print(g)
     L=(g[1])
     print(L)

OUTPUT:

('1', 2)

2

('2', 18)

18

('3', 18)

18

('4', 13)

13

Hector
  • 1
  • 1
  • 1
    Because g[1] is len(...), not the items. – Jeppe Mar 17 '22 at 18:12
  • The error is unrelated to your question and is given because value is not iterable, but an int. We therefore need to know more about what you are putting in (G). But your initial question is answered above. If it's not true what I am saying, please give us a whole minimal example. – Natan Mar 17 '22 at 18:20

2 Answers2

0

following the answer from this post

we can use max() with either itemgetter() or a lambda function

Without knowing much about your data I can only provide a reference.

Best of luck!

Benjamin Diaz
  • 141
  • 1
  • 10
0

Maximum of tuples is max(tuples)

L = (1,2,3,4,5)
print(max(L)) # 5
Natan
  • 728
  • 1
  • 7
  • 23