In R, I can quickly create a list of sequential and non-sequential numbers like so:
numbers <- c(1:5, 8, 12, 15:19)
numbers
[1] 1 2 3 4 5 8 12 15 16 17 18 19
Is there a similar method in Python? Everything I’ve seen seems to require a loop and/or multiple mechanisms to create this.
>Solution :
You can expand a range out into a list.
>>> [*range(1, 6), 8, 12, *range(15, 20)]
[1, 2, 3, 4, 5, 8, 12, 15, 16, 17, 18, 19]