I have a dictionary d like so:

d = {
    (1, 3): False,
    (4, 0): False,
    (0, 7): True
}

Now I want to get the highest y coordinate from the dictionary's keys:

h = max(d, lambda p: p[1])

But this raises an error:

TypeError: unorderable types: function() > dict()

What am I doing wrong?

有帮助吗?

解决方案

You forgot the key keyword.

h = max(d, key=lambda p: p[1])
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top