rahulshr
rahulshr

Reputation: 181

C++ sort code to python sorted

I am trying to convert below C++ code to python expecially the sorting logic using sorted function but how can I pass two values in key parameter of sorted function

//vector<string> str contains some values
sort(str.begin(), str.end(), compareNum);

bool compareNum(string a, string b) {
   return a + b > b + a;
}

How to convert above code using sorted function in python

Upvotes: 1

Views: 1413

Answers (1)

Emanuele Paolini
Emanuele Paolini

Reputation: 10162

You should not use the key parameter but the cmp parameter. https://wiki.python.org/moin/HowTo/Sorting#The_Old_Way_Using_the_cmp_Parameter

Upvotes: 2

Related Questions