-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex50_zan8.py
41 lines (29 loc) · 901 Bytes
/
ex50_zan8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from time import time, sleep
from functools import wraps
def to_string(func):
@wraps(func)
def wrapper(*args, **kwargs):
args = [ f'{v}' for v in args]
return func(*args, **kwargs)
return wrapper
def add_brackets(left='[', right=']'):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
args = [ f'{left}{v}{right}' for v in args]
return func(*args, **kwargs)
return wrapper
return decorator
@add_brackets(left='<',right='>')
@to_string
def concat(*args, **kwargs):
'''concatenate list elements with sep'''
sep = kwargs.get('sep', ';')
return sep.join(args)
if __name__ == '__main__':
users = ['anna', 'maria', 'markus', 'jane']
values = [11, 12, 34, 6]
print(concat(*users))
print(concat(*users, sep=' | '))
print(concat(*values, sep=','))
print('---')