Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dir =["A1","A2","A10","A3"]
- sorted(dir)
- ["A1","A2","A3","A10"]
- ["A1", "A10", "A2", "A3"]
- >>> sorted(dir, key=lambda x: int(x[1:]))
- ['A1', 'A2', 'A3', 'A10']
- >>> dir.append('B12')
- >>> sorted(dir, key=lambda x: (x[0],int(x[1:])))
- ['A1', 'A2', 'A3', 'A10', 'B12']
Add Comment
Please, Sign In to add comment