Re: A dumb question about a class

2007-08-14 Thread [EMAIL PROTECTED]
On Aug 13, 3:30 am, Steven Bethard [EMAIL PROTECTED] wrote: Dick Moores wrote: At 03:35 PM 8/12/2007, Steven Bethard wrote: Note that if you just want to iterate over all the primes, there's no need for the class at all. Simply write:: forprimein iter_primes(): Even if I want to

Re: A dumb question about a class

2007-08-14 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Also, does anyone know if there is some magic that makes i in some_set loads faster than i in some_list It's not magic, per se. It's really part of the definition of the data type. Lists are ordered, and are slow when checking containment. Sets are unordered and

A dumb question about a class

2007-08-12 Thread Dick Moores
I'm still trying to understand classes. I've made some progress, I think, but I don't understand how to use this one. How do I call it, or any of its functions? It's from the Cookbook, at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523048. Thanks, Dick Moores

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: I'm still trying to understand classes. I've made some progress, I think, but I don't understand how to use this one. How do I call it, or any of its functions? It's from the Cookbook, at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523048. The short answer is

Re: A dumb question about a class

2007-08-12 Thread Dick Moores
At 03:09 PM 8/12/2007, Steven Bethard wrote: Here's how I'd write the recipe:: import itertools def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) # generate primes forever while True:

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: At 03:09 PM 8/12/2007, Steven Bethard wrote: Here's how I'd write the recipe:: import itertools def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) # generate primes forever

Re: A dumb question about a class

2007-08-12 Thread Dick Moores
At 03:35 PM 8/12/2007, Steven Bethard wrote: Note that if you just want to iterate over all the primes, there's no need for the class at all. Simply write:: for prime in iter_primes(): Even if I want to test only 1 integer, or want the list of primes in a certain interval, I don't need

Re: A dumb question about a class

2007-08-12 Thread Dustan
On Aug 12, 5:09 pm, Steven Bethard [EMAIL PROTECTED] wrote: def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) # generate primes forever while True: # get the first number from the

Re: A dumb question about a class

2007-08-12 Thread Dustan
On Aug 12, 7:35 pm, Dustan [EMAIL PROTECTED] wrote: On Aug 12, 5:09 pm, Steven Bethard [EMAIL PROTECTED] wrote: def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) # generate primes forever while

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dustan wrote: On Aug 12, 7:35 pm, Dustan [EMAIL PROTECTED] wrote: On Aug 12, 5:09 pm, Steven Bethard [EMAIL PROTECTED] wrote: def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) # generate primes forever

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Dick Moores wrote: At 03:35 PM 8/12/2007, Steven Bethard wrote: Note that if you just want to iterate over all the primes, there's no need for the class at all. Simply write:: for prime in iter_primes(): Even if I want to test only 1 integer, or want the list of primes in a certain

Re: A dumb question about a class

2007-08-12 Thread Steven Bethard
Steven Bethard wrote: Dustan wrote: On Aug 12, 7:35 pm, Dustan [EMAIL PROTECTED] wrote: On Aug 12, 5:09 pm, Steven Bethard [EMAIL PROTECTED] wrote: def iter_primes(): # an iterator of all numbers between 2 and +infinity numbers = itertools.count(2) #