Re: [Tutor] Geometric sequence

2013-11-08 Thread Peter O'Doherty
To the people who kindly replied to my question: many thanks! On 10/31/2013 06:29 PM, Danny Yoo wrote: As an aside: It shouldn't be too bad to write a "generator" for the geometric series, so that we can pick out the terms on-demand. # >>> def geometric(base):

Re: [Tutor] Geometric sequence

2013-10-31 Thread Danny Yoo
As an aside: It shouldn't be too bad to write a "generator" for the geometric series, so that we can pick out the terms on-demand. # >>> def geometric(base): ... x = 1 ... while True: ... yield x ... x *= base ... >>> twos = geometric(2)

Re: [Tutor] Geometric sequence

2013-10-31 Thread Andreas Perstinger
On 31.10.2013 04:00, bob gailer wrote: On 10/30/2013 1:08 PM, Peter O'Doherty wrote: Hi List, I know a geometric sequence can be produced by: series = [2**x for x in range(7)] But I would like to curtail the sequence before the last element excedes a certain value. import itertools series =

Re: [Tutor] Geometric sequence

2013-10-30 Thread bob gailer
On 10/30/2013 1:08 PM, Peter O'Doherty wrote: Hi List, I know a geometric sequence can be produced by: series = [2**x for x in range(7)] But I would like to curtail the sequence before the last element excedes a certain value. import itertools series = [2**x for x in itertools.takewhile(lamb

Re: [Tutor] Geometric sequence

2013-10-30 Thread Dave Angel
On 30/10/2013 13:08, Peter O'Doherty wrote: > Hi List, > > I know a geometric sequence can be produced by: > > series = [2**x for x in range(7)] > > But I would like to curtail the sequence before the last element excedes > a certain value. Is there a better way of doing it that the following: >

Re: [Tutor] Geometric sequence

2013-10-30 Thread Oscar Benjamin
On Oct 31, 2013 12:10 AM, "Mark Lawrence" wrote: > > On 30/10/2013 17:08, Peter O'Doherty wrote: >> >> Hi List, >> >> I know a geometric sequence can be produced by: >> >> series = [2**x for x in range(7)] >> >> But I would like to curtail the sequence before the last element excedes >> a certain

Re: [Tutor] Geometric sequence

2013-10-30 Thread Mark Lawrence
On 30/10/2013 17:08, Peter O'Doherty wrote: Hi List, I know a geometric sequence can be produced by: series = [2**x for x in range(7)] But I would like to curtail the sequence before the last element excedes a certain value. Is there a better way of doing it that the following: for x in range

Re: [Tutor] Geometric sequence

2013-10-30 Thread Alan Gauld
On 30/10/13 17:08, Peter O'Doherty wrote: Hi List, I know a geometric sequence can be produced by: series = [2**x for x in range(7)] But I would like to curtail the sequence before the last element excedes a certain value. You can add an if clause to the comprehension: series = [2**x for x

[Tutor] Geometric sequence

2013-10-30 Thread Peter O'Doherty
Hi List, I know a geometric sequence can be produced by: series = [2**x for x in range(7)] But I would like to curtail the sequence before the last element excedes a certain value. Is there a better way of doing it that the following: for x in range(20): series_element = 2**x print s