Build a List From a Range

Easy ⏱ 8 min 88% acceptance ★★★★☆ 4.2
Write build_range_list(n) that returns a list containing the integers 1 through n (inclusive), in order. If n is less than 1, return an empty list.

Examples

Example 1
Input
n = 5
Output
[1, 2, 3, 4, 5]
Explanation

Integers from 1 to 5 inclusive.

Example 2
Input
n = 0
Output
[]
Explanation

No positive integers to include.

Constraints

  • -1000 <= n <= 1000

Topics

ListsCreation

Companies

AmazonTCSInfosys

Hints

Hint 1

range(1, n + 1) produces the right sequence.

Hint 2

Convert the range object to a list with list().

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.