Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating number Sequence Python

I want to generate a number sequence that repeats 2 consective numbers twice then skips a number and repeats the sequence wihin the range specified.

such as

0,0,1,1,3,3,4,4,6,6,7,7 and so forth.

what I have so far

numrange = 10
numsequence  = [i for i in range(numrange) for _ in range(2)]
numsequence

which produces

[0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]

which is close but not quite what I want

like image 321
Spooked Avatar asked May 20 '26 10:05

Spooked


1 Answers

You can iterate over numbers with the step 3:

[i + j for i in range(0, numrange, 3) for j in (0, 0, 1, 1)]

Output:

[0, 0, 1, 1, 3, 3, 4, 4, 6, 6, 7, 7, 9, 9, 10, 10]
like image 144
Yevhen Kuzmovych Avatar answered May 22 '26 00:05

Yevhen Kuzmovych