On 04/25/2008 01:09 AM, Dennis Lee Bieber wrote:
On Thu, 24 Apr 2008 21:31:15 -0300, Rogério Brito [EMAIL PROTECTED]
declaimed the following in comp.lang.python:
a = [i for i in range(0,n+1)]
Uhm... At least in 2.4 and earlier, range() returns a list... No
need for the list-comp in
On 04/25/2008 01:30 AM, Steve Holden wrote:
Rogério Brito wrote:
I'm just getting my feet wet on Python and, just for starters, I'm
coding some elementary number theory algorithms (yes, I know that most
of them are already implemented as modules, but this is an exercise in
learning the
On 04/25/2008 05:00 AM, John Machin wrote:
On Apr 25, 5:44 pm, Robert Bossy [EMAIL PROTECTED] wrote:
If the OP insists in not examining a[0] and a[1], this will do exactly
the same as the while version:
for p in a[2:]:
if p:
print p
... at the cost of almost doubling the amount
On 04/25/2008 09:30 AM, Nick Craig-Wood wrote:
When you are up to speed in python I suggest you check out gmpy for
number theory algorithms.
Thanks. That is quite useful to know when I don't want to code explicitly the
details of the algorithm.
Thanks, Rogério.
--
Rogério Brito : [EMAIL
Rogério Brito wrote:
i = 2
while i = n:
if a[i] != 0:
print a[i]
i += 1
You can spell this as a for-loop:
for p in a:
if p:
print p
It isn't exactly equivalent, but gives the same output as we know that a[0]
and a[1] are also 0.
Peter
--
Peter Otten wrote:
Rogério Brito wrote:
i = 2
while i = n:
if a[i] != 0:
print a[i]
i += 1
You can spell this as a for-loop:
for p in a:
if p:
print p
It isn't exactly equivalent, but gives the same output as we know that a[0]
and a[1] are also 0.
On Apr 25, 5:44 pm, Robert Bossy [EMAIL PROTECTED] wrote:
Peter Otten wrote:
Rogério Brito wrote:
i = 2
while i = n:
if a[i] != 0:
print a[i]
i += 1
You can spell this as a for-loop:
for p in a:
if p:
print p
It isn't exactly equivalent, but
John Machin wrote:
On Apr 25, 5:44 pm, Robert Bossy [EMAIL PROTECTED] wrote:
Peter Otten wrote:
Rogério Brito wrote:
i = 2
while i = n:
if a[i] != 0:
print a[i]
i += 1
You can spell this as a for-loop:
for p in a:
if p:
print p
Rogério Brito:
Hi, All.
I'm just getting my feet wet on Python and, just for starters, I'm coding some
elementary number theory algorithms (yes, I know that most of them are already
implemented as modules, but this is an exercise in learning the language
idioms).
As you can see from the
also, i would recommend you to visit projecteuler.net
you can solve math tasks and then see how others have done the same.
you can fetch very good and pythonic solution there.
--
http://mail.python.org/mailman/listinfo/python-list
hellt [EMAIL PROTECTED] writes:
my variant of the sieve
Since you posted it, you are also looking for advice to improve your
code ;)
def GetPrimes(N):
arr = []
for i in range(1,N+1):
arr.append(i)
This is the same as:
arr = range(1, N+1)
!-)
#Set first item to
On 25 апр, 13:29, Arnaud Delobelle [EMAIL PROTECTED] wrote:
hellt [EMAIL PROTECTED] writes:
my variant of the sieve
Since you posted it, you are also looking for advice to improve your
code ;)
def GetPrimes(N):
arr = []
for i in range(1,N+1):
arr.append(i)
This is
On Fri, 25 Apr 2008 10:24:16 +0200, Robert Bossy wrote:
John Machin wrote:
On Apr 25, 5:44 pm, Robert Bossy [EMAIL PROTECTED] wrote:
Peter Otten wrote:
If the OP insists in not examining a[0] and a[1], this will do exactly
the same as the while version:
for p in a[2:]:
if p:
On 25 апр, 15:02, Max M [EMAIL PROTECTED] wrote:
Rogério Brito skrev:
Hi, All.
What I would like is to receive some criticism to my code to make it
more Python'esque and, possibly, use the resources of the computer in a
more efficient way (the algorithm implemented below is the Sieve of
Rogério Brito skrev:
Hi, All.
What I would like is to receive some criticism to my code to make it
more Python'esque and, possibly, use the resources of the computer in a
more efficient way (the algorithm implemented below is the Sieve of
Eratosthenes):
I agree with the rest here. Your
Rogério Brito [EMAIL PROTECTED] wrote:
I'm just getting my feet wet on Python and, just for starters, I'm coding
some
elementary number theory algorithms (yes, I know that most of them are
already
implemented as modules, but this is an exercise in learning the
language idioms).
When
hellt skrev:
Most code is not like that so perhaps you should try something more
usual like sending email, fetching webpages etc. to get a feel for the
language.
em, i would say, that python (esp. with NumPy+Psyco) is very popular
in numerical processing also.
I know, and I might be way
Marc 'BlackJack' Rintsch wrote:
Indeed. Would it be a sensible proposal that sequence slices should
return an iterator instead of a list?
I don't think so as that would break tons of code that relies on the
current behavior. Take a look at `itertools.islice()` if you want/need
an
Hi, All.
I'm just getting my feet wet on Python and, just for starters, I'm coding some
elementary number theory algorithms (yes, I know that most of them are already
implemented as modules, but this is an exercise in learning the language idioms).
As you can see from the code below, my
What I would like is to receive some criticism to my code to make it more
Python'esque and, possibly, use the resources of the computer in a more
efficient way (the algorithm implemented below is the Sieve of Eratosthenes):
It looks like straight-forward code and is fine as it stands.
If you
Rogério Brito wrote:
Hi, All.
I'm just getting my feet wet on Python and, just for starters, I'm
coding some elementary number theory algorithms (yes, I know that most
of them are already implemented as modules, but this is an exercise in
learning the language idioms).
As you can see from
On Apr 24, 11:09 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
On Thu, 24 Apr 2008 21:31:15 -0300, Rogério Brito [EMAIL PROTECTED]
declaimed the following in comp.lang.python:
a = [i for i in range(0,n+1)]
Uhm... At least in 2.4 and earlier, range() returns a list... No
need for
22 matches
Mail list logo