Home > Net >  Is there a way to get the largest value from tuples in python?
Is there a way to get the largest value from tuples in python?

Time:03-18

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

CodePudding user response:

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!

CodePudding user response:

Maximum of tuples is max(tuples)

L = (1,2,3,4,5)
print(max(L)) # 5
  • Related