Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add non-sequential numbers to a range?

Tags:

python

range

I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers:


>>> for x in range(750, 765), 769, 770, 774: print x
... 
[750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764]
769
770
774

How can I get all the numbers in a single list?

like image 846
adam Avatar asked Mar 24 '09 17:03

adam


1 Answers

Use the built-in + operator to append your non-sequential numbers to the range.

for x in range(750, 765) + [769, 770, 774]: print x
like image 133
Jason Coon Avatar answered Sep 18 '22 06:09

Jason Coon