Relative Content

Tag Archive for pythonmax

max() with key argument python

I know a bit about how key argument is used in python max(). max(("pyth", "lua", "ruby"), key=len) will return pyth and ruby. However, max((31, 13, 11), key=lambda x: sum(int(i) for i in str(x))) will only give me 31 (13 should be returned as well), or max((13, 31, 11), key=lambda x: sum(int(i) for i in str(x))) will only give me 13 (31 should be returned as well). Can someone explain this? Many thanks.