Guest User

Untitled

a guest
Dec 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. y = []
  2. while True:
  3. user_input = input('type text')
  4. divide_string = user_input.split()
  5.  
  6. for x in divide_string:
  7. y.append(x)
  8. if user_input == '':
  9. break
  10. else:
  11. continue
  12.  
  13. print(" ".join(sorted(y)))
  14.  
  15. import string
  16. ...
  17. punctuation_map = {ord(char): None for char in string.punctuation}
  18. while True:
  19. user_input = input('type text')
  20. clean_data = user_input.translate(punctuation_map)
  21. divide_string = clean_data.split()
  22. ...
  23.  
  24. import re
  25.  
  26. # исходные данные
  27. user_input = 'type text. hello'
  28. # с помощью регулярных выражений извлечем только слова длиной больше 3 символов
  29. worlds = re.findall('w{3,}', user_input)
  30. # сортируем и выводим
  31. print(sorted(worlds))
  32.  
  33. ['hello', 'text', 'type']
  34.  
  35. y = []
  36. while True:
  37. user_input = input('type text: ')
  38. divide_string = user_input.split()
  39.  
  40. for x in divide_string:
  41. y.append(x.replace('.', ''))
  42. if user_input == '':
  43. break
  44. else:
  45. continue
  46.  
  47. print(" ".join(sorted(y)))
  48.  
  49. from string import punctuation
  50.  
  51. def y(lj=lambda w: ''.join(s for s in w if s not in punctuation)):
  52. user_input = input('type text')
  53. while user_input:
  54. yield from map(lj, user_input.split())
  55. user_input = input('type text')
  56.  
  57. print(*sorted(y()))
Add Comment
Please, Sign In to add comment