We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Key argument is a function which takes in the value and returns how important the value is.
For example, if key is
lambda x = -x
Then, the larger the value is, the less the importance gets. In this case, you can sort the array in reverse order.
Gr4d4m's key will turn each character in the string into a tuple, and then let the the sorted function compares each character according to the tuple instead of the character itself.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
ginortS
You are viewing a single comment's thread. Return to all comments →
Key argument is a function which takes in the value and returns how important the value is.
For example, if key is
Then, the larger the value is, the less the importance gets. In this case, you can sort the array in reverse order.
Gr4d4m's key will turn each character in the string into a tuple, and then let the the sorted function compares each character according to the tuple instead of the character itself.