a=[(‘jatin’,5),(‘prateek’,10),(‘ram’,1),(‘arnav’,20)]
def key(q):
return q[1]
x=sorted(a,key=key)
print(x)
I want to ask as we have to pass 2nd argument in sorted as a key function so why don’t we write key=key() instead of key=key and how are the tuple objects are being passed in key function like (‘jatin’,5).