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
[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
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
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
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:
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
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
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
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
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
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
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)
#
12 matches
Mail list logo