我要把这张单子分类
list = ['16. Michlík', '4. and 65. Bichakhchyan', '15. Pavol']
根据每个字符串的第一个数字。所以输出应该是这样的
list = ['4. and 65. Bichakhchyan', '15. Pavol', '16. Michlík']
这是我到目前为止所做的,但是当字符串中有一个以上的数字时,它就不起作用了
sorted(list, key=lambda x : x[:x.find(".")])
你们能帮帮我吗?你知道吗
Tags:
必须将模式强制转换为整数,否则将其作为字符串进行比较。你知道吗
您可以使用正则表达式:
输出:
这是一种方法。你知道吗
相关问题 更多 >
编程相关推荐