반응형
Create a function with two arguments that will return an array of the first n multiples of x.
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array or list ( depending on language ).
Examples
count_by(1,10) #should return [1,2,3,4,5,6,7,8,9,10]
count_by(2,5) #should return [2,4,6,8,10]
Solution:
def get_range_index(func):
def wrapper(x, n):
def get_index(n):
for i in range(1, n+1):
yield i
return func(x, get_index(n))
return wrapper
@get_range_index
def count_by(x: int, i: callable) -> List[int]:
return [x*y for y in i]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0909. Will there be enough space? (0) | 2022.09.09 |
---|---|
0908. Sorted? yes? no? how? (0) | 2022.09.08 |
0906. The Coupon Code (0) | 2022.09.06 |
0905. Training JS #7: if..else and ternary operator (0) | 2022.09.05 |
0904. No zeros for heros (0) | 2022.09.04 |