I'm trying to sort a list alphabetically, where capital letters should come before lower case letters.
l = ['a', 'b', 'B', 'A']
sorted(l)
should result in ['A','a','B','b']
I've tried these two forms, but to no avail;
>>> sorted(l, key=lambda s: s.lower())
['a', 'A', 'b', 'B']
>>> sorted(l, key=str.lower)
['a', 'A', 'b', 'B']
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…