On 10/11/2010 17:34, xoff wrote:
On 10 nov, 18:15, Paul Rubin<no.em...@nospam.invalid>  wrote:
you could use itertools.chain:

   from itertools import chain

   for i in chain(range(3,7), range(17,23)):
     ...

I'm assuming you're using python 3.  In python 2 each of those ranges
expands immediately to a list, so on the one hand they're consuming
potentially lots of storage (you should use xrange instead).  On the
other hand you could just concatenate the lists with +, but I wouldn't
advise that.

I am curious, why wouldn't you advise something like this:
for i in chain(range(3,7) + range(17,23)):

In Python 3 'range' is a generator, like 'xrange' in Python 2.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to