Advertisement
enkryptor

Untitled

Jan 26th, 2022
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. change_word = 'хлеб'
  2. def decorator(word_or_func='колбаса'):
  3.     def decore(func, *args):
  4.         arg_list = [func, *args] if not callable(func) else args
  5.         func = word_or_func if callable(word_or_func) else func
  6.         new_word = word_or_func if type(word_or_func) == str else 'колбаса'
  7.         def wrapper(*arg_list):
  8.             some_list = list(arg_list)
  9.             return_list = []
  10.             for phrase in some_list:
  11.                 if change_word in phrase:
  12.                     return_list.append(phrase.replace(change_word, new_word, -1))
  13.                 else:
  14.                     return_list.append(phrase)
  15.             return func(*return_list)
  16.         return wrapper(*arg_list) if callable(word_or_func) else wrapper
  17.  
  18.     return decore
  19.  
  20. @decorator()
  21. def text(*args):
  22.     print(*args, sep='\n', end='\n')
  23.  
  24. text('хлеб всему голова', 'хлеб-соль', 'хлебное место', 'без соли хлеб не еда')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement