webbersof

Text Processing

Jul 13th, 2022
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. # Зад.1
  2. def reverse_func(data):
  3.     for string in data:
  4.         print(f'{string} = {string[::-1]}')
  5.  
  6. words = []
  7.  
  8. while True:
  9.     word = input()
  10.  
  11.     if word == 'end':
  12.         break
  13.     words.append(word)
  14.  
  15. reverse_func(words)
  16.  
  17.  
  18.  
  19. # Зад.2
  20. class Example:
  21.     def __init__(self, words):
  22.         self.words = words
  23.  
  24.     def repeat_func(self):
  25.         return ''.join(map(lambda x: x * len(x), self.words))
  26.  
  27. words: list = input().split(' ')
  28. obj = Example(words)
  29. print(obj.repeat_func())
  30.  
  31.  
  32.  
  33.  
  34.  
  35. # Зад.3
  36. def replace_all_occurrences(first_string, second_string):
  37.     while first_string in second_string:
  38.         second_string = second_string.replace(first_string, '')
  39.  
  40.     return second_string
  41.  
  42. print(replace_all_occurrences(input(), input()))
  43.  
  44.  
  45.  
  46. # Зад.4
  47. banned_words = input().split(', ')
  48. text = input()
  49.  
  50. for word in banned_words:
  51.     text = text.replace(word, '*' * len(word))
  52.  
  53. print(text)
  54.  
  55.  
  56.  
  57. # Зад.5
  58. def get_digits(data):
  59.     return ''.join([str(ch) for ch in data if ch.isdigit()])
  60.  
  61. def get_letters(data):
  62.     return ''.join([ch for ch in data if ch.isalpha()])
  63.  
  64. def get_other_signs(data):
  65.     return ''.join([ch for ch in data if not ch.isalpha() and not ch.isdigit()])
  66.  
  67. data = input()
  68. print(get_digits(data))
  69. print(get_letters(data))
  70. print(get_other_signs(data))
  71.  
Advertisement
Add Comment
Please, Sign In to add comment