-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
73 lines (62 loc) · 1.31 KB
/
tasks.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# task 1
import requests
# def split_list(numbers: list, divisor: int) -> list:
# new_list = []
# for i in range(0, len(numbers), divisor):
# new_list.append(numbers[i: i + divisor])
# return new_list
#
#
# assert split_list([1, 2, 3, 4], 2) == [
# [1, 2],
# [3, 4],
# ]
# assert split_list([1, 2, 3, 4, 5, 6], 2) == [
# [1, 2],
# [3, 4],
# [5, 6],
# ]
# assert split_list([1, 2, 3, 4, 5, 6], 3) == [
# [1, 2, 3],
# [4, 5, 6],
# ]
# assert split_list([1, 2, 3, 4, 5], 3) == [
# [1, 2, 3],
# [4, 5],
# ]
# assert split_list([1, 2, 3, 4, 5], 2) == [
# [1, 2],
# [3, 4],
# [5, ],
# ]
# assert split_list([1, 2, 3, 4, 5], 10) == [
# [1, 2, 3, 4, 5],
# ]
# assert split_list([], 2) == [
# ]
def lru_cache(function):
CACHE = {}
def wrapper(*args, **kwargs):
key = f'{function.__name__}::{args}-{kwargs}'
print(CACHE)
if key in CACHE:
return CACHE[key]
from time import sleep
sleep(2)
result = function(*args, **kwargs)
CACHE[key] = result
return result
return wrapper
@lru_cache
def add(x, y):
return x + y
@lru_cache
def foo():
return 1
print(add(2, 5))
print(add(2, 5))
# print(add(2, y=5))
# print(add(3, 4))
# print(add(3, 5))
# print(foo())
# print(add(3, 4))