This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
我正在尝试对该列表进行排序['a', '2%20q']我希望看到['2%20q', 'a'],但是下面的代码会生成['a', '2%20q'](保留完整的初始列表)

sorted(['a', '2%20q']) // output: ['a', '2%20q']

最佳答案

sorted(['a','2%20q'], key=lambda x: 0 if x == '2%20q' else 1)

关于python - 在python中对字符串进行排序不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15594455/

10-12 21:07