Re: multiple discontinued ranges

2010-11-11 Thread cbr...@cbrownsystems.com
On Nov 10, 10:02 am, Mel wrote: > xoff wrote: > > 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

Re: multiple discontinued ranges

2010-11-10 Thread Paul Rubin
xoff writes: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): First of all, the outer chain does nothing. Second, concatenating the two lists creates a new list, consuming storage and taking time copying all the elements. Third, if there

Re: multiple discontinued ranges

2010-11-10 Thread MRAB
On 10/11/2010 17:34, xoff wrote: On 10 nov, 18:15, Paul Rubin 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

Re: multiple discontinued ranges

2010-11-10 Thread Emile van Sebille
On 11/10/2010 9:34 AM xoff said... On 10 nov, 18:15, Paul Rubin wrote: 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 c

multiple discontinued ranges

2010-11-10 Thread xoff
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 t

Re: multiple discontinued ranges

2010-11-10 Thread Paul Rudin
xoff 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 >

Re: multiple discontinued ranges

2010-11-10 Thread Mel
xoff wrote: > 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 >

Re: multiple discontinued ranges

2010-11-10 Thread Nobody
On Wed, 10 Nov 2010 09:34:14 -0800, xoff wrote: > I am curious, why wouldn't you advise something like this: > for i in chain(range(3,7) + range(17,23)): Because it constructs all three lists (both of the individual ranges and their concatenation) in memory. For a trivial example, that isn't a pr

Re: multiple discontinued ranges

2010-11-10 Thread xoff
On 10 nov, 18:15, Paul Rubin 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 con

Re: multiple discontinued ranges

2010-11-10 Thread xoff
On 10 nov, 18:13, Paul Rudin wrote: > xoff 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): >

Re: multiple discontinued ranges

2010-11-10 Thread Peter Otten
xoff wrote: > 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 >

Re: multiple discontinued ranges

2010-11-10 Thread Paul Rubin
xoff 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. you could use itertools.chain: from itertools import chain for i in chain(range(3,7), range(17,23)): ... I'm assuming you're usi