나는 이렇게 학습한다/Algorithm & SQL

What is between?

daco2020 2022. 7. 24. 00:56
반응형

Complete the function that takes two integers (a, b, where a < b) and return an array of all integers between the input parameters, including them.

For example:

a = 1
b = 4
--> [1, 2, 3, 4]

 

Solution:

def between(a,b):
    number = get_number_generater(range(a,b+1))
    return [next(number) for i in range(b+1-a)]
    
def get_number_generater(range):
    for i in range:
        yield i

Solve it using a generator.

 

 

It can be done more easily as shown below.

def between(a,b):
    return list(range(a,b+1))

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Calculate BMI  (0) 2022.07.25
Check the exam  (0) 2022.07.24
Replace With Alphabet Position  (0) 2022.07.22
Anagram Detection  (0) 2022.07.21
Sum of all the multiples of 3 or 5  (0) 2022.07.20