Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 17.18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from collections import Counter

def lower(func):

def _lower(*args):
args_lower = ''
for arg in args:
args_lower += arg.lower()
y = func(args_lower)

return y

return _lower

@lower
def count(s):
return Counter(s)

if __name__ == '__main__':
s = 'abcdABCefgGFAB'
g = 'qQQqqwerERwww'
print(count(s, g))
48 changes: 48 additions & 0 deletions 17.20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
def check_type(*typechecker):

def _check_type(func):

def __check_type(*args, **kwargs):

try:
if len(typechecker) != len(args):
raise TypeError('Amounts do not match')
except TypeError:
return TypeError('Amounts do not match')

try:
for i, t in zip(args, typechecker):
if type(i) != t:
raise TypeError('Types do not match')
except TypeError:
return TypeError('Types do not match')

y = func(*args, **kwargs)
return y

return __check_type

return _check_type

class TypeError(Exception):

def __init__(self, msg):
super().__init__()
self.msg = msg

def __str__(self):
return self.msg

@ check_type(int, str, tuple)
def func(a, b, c):
return f'| {a} | {b} | {c} |'


if __name__ == '__main__':
print(func(22, 'hello', (1, 'hi', 2)))
print(func(22.5, 'hello', (1, 'hi', 2)))
print(func(22,'hello world'))