gpt4 book ai didi

python - C++ 排序代码到 python 排序

转载 作者:行者123 更新时间:2023-11-28 06:00:52 26 4
gpt4 key购买 nike

我正在尝试将下面的 C++ 代码转换为 python,特别是使用排序函数的排序逻辑,但是我如何在排序函数的关键参数中传递两个值

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

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

如何在python中使用sorted函数转换上述代码

最佳答案

您不应使用key 参数,而应使用cmp 参数。 https://wiki.python.org/moin/HowTo/Sorting#The_Old_Way_Using_the_cmp_Parameter

关于python - C++ 排序代码到 python 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33315649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com