time complexity of cmp_to_key() ? and how do it work?

Viewed 7

how does cmp_to_key() work ? does it compare every element to all of the other elements? making its complexity n^2 ?

For example, I'm trying to concatenate the integer elements of a list, and making the largest value out from them.

a=[3,30,34,5,9]
b=sorted(map(str,a),key=cmp_to_key(lambda x,y: int(y+x) - int(x+y)))
b is now: ['9', '5', '34', '3', '30'] 

I know the time complexity of sorted() is O(n Log n), but adding the key function of cmp_to_key(), what is the final time time complexity ? does it make it O(n^3 Log n) ?

0 Answers
Related