Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. ['z+2-44', '4+55+z+88']
  2.  
  3. [['z','+','2','-','44'],['4','+','55','+','z','+','88']]
  4.  
  5. import re
  6. lst = ['z+2-44', '4+55+z+88']
  7. [re.findall('w+|W+', s) for s in lst]
  8. # [['z', '+', '2', '-', '44'], ['4', '+', '55', '+', 'z', '+', '88']]
  9.  
  10. z = ['z+2-44', '4+55+z+88']
  11.  
  12. print([["".join(x) for k,x in itertools.groupby(i,str.isalnum)] for i in z])
  13.  
  14. [['z', '+', '2', '-', '44'], ['4', '+', '55', '+', 'z', '+', '88']]
  15.  
  16. l = ['z+2-44', '4+55+z+88']
  17. print([list(filter(None, re.split(r'(w+)', i))) for i in l])
  18.  
  19. [['z', '+', '2', '-', '44'], ['4', '+', '55', '+', 'z', '+', '88']]
  20.  
  21. In [34]: lst = ['z+2-44', '4+55+z+88']
  22.  
  23. In [35]: [s.replace('+', ' + ').replace('-', ' - ').split() for s in lst]
  24. Out[35]: [['z', '+', '2', '-', '44'], ['4', '+', '55', '+', 'z', '+', '88']]
  25.  
  26. >>> testing = 'z+2-44'
  27. >>> testing.split('+')
  28. ['z', '2-44']
  29. >>> testing.split('-')
  30. ['z+2', '44']
  31.  
  32. import re
  33.  
  34. >>> re.split('+|-', testing)
  35. ['z', '2', '44']
  36.  
  37. >>> re.split('[^a-zA-Z0-9]', testing)
  38. ['z', '2', '44']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement