I want one long list, say [1,2,3,4,5,15,16,17,18,19] as an example. To initialize this, I try typing:
new_list = [range(1,6),range(15,20)]
range
returns a list to begin with, so you need to either concatenate them together with +
or use append()
or extend()
.
new_list = range(1,6) + range(15,20)
or
new_list = range(101,6284)
mew_list.extend([8001,8003,8010])
mew_list.extend(range(10000,12322))
Alternatively, you could use itertools.chain()
as shown in Shawn Chin's answer.