Re: [coders] [python] for... while loop

2006-06-15 Thread Andrew Bennetts
On Wed, Jun 14, 2006 at 03:33:31PM +1000, Tim Leslie wrote: [...] > You can have generators which look like list comprehensions, but they > still have the same problem of the if statement only acting as a > filter, not a stopping condition. If you wanted it to work you'd have > to shift your condit

RE: [coders] [python] for... while loop

2006-06-14 Thread Adelle Hartley
Tim Leslie wrote: > Here's my current musings on "new python syntax features that > would be really, really, cool". > My use case for this was doing stuff with prime numbers where > you'd want to take the first however many from a big list of > primes, e.g[3]. > > def is_prime(n, primes): >

Re: [coders] [python] for... while loop

2006-06-13 Thread Tim Leslie
On 6/14/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote: This one time, at band camp, Tim Leslie wrote: >On 6/14/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote: >>List comprehensions! >> >>>def is_prime(n, primes): >>> """ primes is a list of primes where sqrt(n) <= max(primes) < n""" >>> for p

Re: [coders] [python] for... while loop

2006-06-13 Thread Martin Pool
On 14/06/2006, at 3:20 PM, Jamie Wilkinson wrote: This one time, at band camp, Tim Leslie wrote: On 6/14/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote: List comprehensions! def is_prime(n, primes): """ primes is a list of primes where sqrt(n) <= max(primes) < n""" for p in primes whi

Re: [coders] [python] for... while loop

2006-06-13 Thread Jamie Wilkinson
This one time, at band camp, Tim Leslie wrote: >On 6/14/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote: >>List comprehensions! >> >>>def is_prime(n, primes): >>> """ primes is a list of primes where sqrt(n) <= max(primes) < n""" >>> for p in primes while p*p <= n: >>> if n % p == 0: >>>

Re: [coders] [python] for... while loop

2006-06-13 Thread Tim Leslie
On 6/14/06, Jamie Wilkinson <[EMAIL PROTECTED]> wrote: List comprehensions! >def is_prime(n, primes): > """ primes is a list of primes where sqrt(n) <= max(primes) < n""" > for p in primes while p*p <= n: > if n % p == 0: > return False > return True > >Does this look like

Re: [coders] [python] for... while loop

2006-06-13 Thread Jamie Wilkinson
This one time, at band camp, Tim Leslie wrote: >Here's my current musings on "new python syntax features that would be >really, really, cool". > >A common idiom[1] when looping is to do something like: > >for i in somelist: > if not condition: > break > do_stuff() > >Wouldn't it be cool[2

Re: [coders] [python] for... while loop

2006-06-13 Thread Andre Pang
On 14/06/2006, at 10:48 AM, Tim Leslie wrote: Here's my current musings on "new python syntax features that would be really, really, cool". A common idiom[1] when looping is to do something like: for i in somelist: if not condition: break do_stuff() Wouldn't it be cool[2] if inst