Domanda

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?

È stato utile?

Soluzione

You forgot the key keyword.

h = max(d, key=lambda p: p[1])
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top