multiple discontinued ranges

xoff igor.idziejczak at gmail.com
Wed Nov 10 12:23:06 EST 2010


On 10 nov, 18:13, Paul Rudin <paul.nos... at rudin.co.uk> wrote:
> xoff <igor.idziejc... at gmail.com> writes:
> > I was wondering what the best method was in Python programming for 2
> > discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23.
> > Am I obliged to use 2 for loops defining the 2 ranges like this:
>
> > for i in range (3,7):
> >  do bla
> > for i in range (7,17):
> >  do bla
>
> > or is there a more clever way to do this?
>
> for i in itertools.chain(xrange(3,7), xrange(17,23)):
>     print i

Thank you, that was exactly what I needed!



More information about the Python-list mailing list