use*_*881 2 python sorting python-2.7
请告诉我如何按升序/降序对字符串列表进行排序,而不考虑特殊字符和大小写.
例如:
list1=['test1_two','testOne','testTwo','test_one']
Run Code Online (Sandbox Code Playgroud)
应用list.sort/sorted方法会生成排序列表
['test1_two', 'testOne', 'testTwo', 'test_one']
Run Code Online (Sandbox Code Playgroud)
但不考虑特殊字符和案例应该是
['testOne','test_one', 'test1_two','testTwo'] OR
['test_one','testOne','testTwo', 'test1_two' ]
Run Code Online (Sandbox Code Playgroud)
list.sort/sorted方法根据字符的ascii值排序但是请告诉我如何实现我期望的一个
如果用特殊字符表示"一切不是字母":
sorted(list1, key=lambda x: re.sub('[^A-Za-z]+', '', x).lower())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2709 次 |
| 最近记录: |