Advertisement
here2share

# b_offsetsorting.py

Dec 10th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # offsetsorting.py
  2.  
  3. import re
  4.  
  5. def remove_digits(z):
  6.     return re.sub('[0-9 \-\?\+\t]', '', z)
  7.  
  8. zzz='''
  9. qqq
  10. - www
  11. 1 eee
  12.                             ++ rrr
  13. 2 ttt
  14. - yyy
  15. uuu
  16. 7 iii
  17.                         ++ ooo
  18. 9 ppp
  19. - aaa
  20. - sss
  21. ddd
  22.                 ++ fff
  23. 6 ggg
  24. hhh
  25. - jjj
  26.                     ++ kkk
  27.             ++ lll
  28.                                     ++ zzz
  29. 3 xxx
  30. 8 ccc
  31. 5 vvv
  32.                     ++ bbb
  33. nnn
  34. - mmm
  35. '''.splitlines()
  36.  
  37. zzz = set(zzz)
  38. zzz = sorted(zzz, key=lambda s: (remove_digits(s), s))
  39. zzz = '\n'.join(zzz)
  40. zzz = re.sub(r'[\t ]{2,}', '\t'*2, zzz)
  41. print zzz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement