Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. [espacios]Elnombre1[espacios](237)
  2. [espacios]Elnombre3(237)
  3. [espacios]Elnombre4(17)
  4.  
  5. with open("e.txt", 'r+') as f:
  6. texto = re.sub('^s+([a-zA-Z-0-9]+)s*', f.read())
  7. f.seek(0)
  8. f.write(texto)
  9. f.truncate()
  10.  
  11. nombres = []
  12. with open("e.txt", "r") as f:
  13. for linea in f:
  14. nombre = linea.split('(')[0].strip()
  15. nombres.append(nombre)
  16. with open("e.txt", "w") as f:
  17. for nombre in nombres:
  18. f.write("{}n".format(nombre))
  19.  
  20. import re
  21.  
  22. lineas = [
  23. ' Elnombre1 (237)',
  24. ' Elnombre3(237)',
  25. ' Elnombre4(17)'
  26. ]
  27.  
  28. nombres = [re.findall('^s+([a-zA-Z-0-9]+)s*', x)[0] for x in lineas]
  29.  
  30. print(nombres)
Add Comment
Please, Sign In to add comment