小编Pok*_*rof的帖子

Python排序最后的字符

在较新的Python中,我可以使用sorted函数,并根据它们的最后几个字符轻松地排序字符串列表:

lots_list=['anything']

print sorted(lots_list, key=returnlastchar)

def returnlastchar(s):     
    return s[10:] 
Run Code Online (Sandbox Code Playgroud)

如何实现上述lots_list.sort()Python(2.3)中使用的上述内容?

"错误:当我尝试使用时sorted(),the global name sorted is not defined."

谢谢!

python sorting string python-2.3

6
推荐指数
2
解决办法
4672
查看次数

Python 2.3仅使用.Sort()按值排序字典

当我们得到的所有内容都是dict.sort()不带参数时,我们如何按Python 2.3中的值对字典进行排序.我可以使用sorted(dict.items(), lambda x, y: cmp(x[1], y[1]), reverse=True)更新的Python 进行排序.

需要的是:示例:

d = {'a':2,'b':1,'c':3}
Run Code Online (Sandbox Code Playgroud)

排序后:

[('c':3),('a':2),('b':1)]
Run Code Online (Sandbox Code Playgroud)

有什么提示吗?谢谢 !

python sorting dictionary python-2.3

0
推荐指数
1
解决办法
1654
查看次数

标签 统计

python ×2

python-2.3 ×2

sorting ×2

dictionary ×1

string ×1