I came across code something like this and am trying to understand how it works. From the python documentation for sorted() the key parameter takes a function which takes a single argument and then returns a key to be used in the comparison. This code is assigning key a class. How is this ok? And how does __lt__ get x and y passed to it?
class K(str):
def __lt__(x, y):
return x > y
input = [3, 30, 7]
sorted(input, key=K)
Output: [7, 30, 3]