Here are my benchmarks for those interested in version 2.4.3
[EMAIL PROTECTED]:~$ python -V
Python 2.4.3
[EMAIL PROTECTED]:~$ python -mtimeit 'for x in range(1000):pass'
1 loops, best of 3: 64.2 usec per loop
[EMAIL PROTECTED]:~$ python -mtimeit 'for x in xrange(1000):pass'
1 loops, best o
Tim Roberts <[EMAIL PROTECTED]> wrote:
...
> xrange used to be better. As I understand it, that's no longer the case.
measuring is better than guessing:
brain:~/codejam alex$ python -V
Python 2.5c1
brain:~/codejam alex$ python -mtimeit 'for x in range(1000):pass'
1 loops, best of 3: 71.9
Steve Holden wrote:
> Nicko wrote:
> > Fredrik Lundh wrote:
> >>if you cannot refrain from pulling arguments out of your ass, you not
> >>really the right person to talk about hygiene.
> >
> > I'm impressed but your mature argument. Clearly, in the face of such
> > compelling reasoning, I shall hav
Nicko wrote:
> Fredrik Lundh wrote:
>
>>Nicko wrote:
>>
>>
>>>... In the case of the idiom "for i in
>>>range(x):..." there absolutely no utility whatsoever in creating and
>>>recording the list of objects.
>>
>>for short lists, both objects create the *same* number of objects.
>
>
> This is tru
Fredrik Lundh wrote:
> Nicko wrote:
>
> > ... In the case of the idiom "for i in
> > range(x):..." there absolutely no utility whatsoever in creating and
> > recording the list of objects.
>
> for short lists, both objects create the *same* number of objects.
This is true for long lists too, if yo
Nicko wrote:
> There's a huge difference between not being profligate with resources
> and premature optimisation. In the case of the idiom "for i in
> range(x):..." there absolutely no utility whatsoever in creating and
> recording the list of objects. Unless it makes a difference to code
> struc
Tim Roberts wrote:
> xrange used to be better. As I understand it, that's no longer
> the case.
for short ranges, range is faster in some Python versions, xrange is
faster in some (including 2.4). the difference is usually very small
(the same number of objects are created in both cases).
f
[EMAIL PROTECTED] wrote:
>AlbaClause wrote:
>
>> for i in range(length):
>> print i
>
>Or usually better:
>
>for ii in xrange(length):
>...
xrange used to be better. As I understand it, that's no longer the case.
--
- Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > I thought the xrange was preferred? for x in xrange(length):
>
> preferred by premature optimization freaks, perhaps.
There's a huge difference between not being profligate with resources
and premature optimisation. In the case of the idiom "f
Putty wrote:
> In C and C++ and Java, the 'for' statement is a shortcut to make very
> concise loops. In python, 'for' iterates over elements in a sequence.
> Is there a way to do this in python that's more concise than 'while'?
>
> C:
> for(i=0; i
>
> python:
> while i < length:
>
[EMAIL PROTECTED] wrote:
> I thought the xrange was preferred? for x in xrange(length):
preferred by premature optimization freaks, perhaps. in practice, if the
range is reasonably small and you're going to loop over all the integers,
it doesn't really matter.
(the range form creates a list an
Kay Schluehr:
> I hate ii ;)
It's not nice looking, I agree. A more explicit name is often better.
But I think ii is better than i because you can find it in the code
(with the Find command of the editor or grep) more easily than i.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/py
`range' is especially useful for iterating over long sequences ;-)
for i in range(0,100) :
OverflowError: range() result has too many items
Sybren Stuvel wrote:
> [EMAIL PROTECTED] enlightened us with:
> > I thought the xrange was preferred? for x in xrange(length):
>
> True. I
> -Original Message-
> From: Kay Schluehr
>
> >
> > python:
> > while i < length:
> > i += 1
>
> As AlbaClause had demonstrated you can iterate over indices as well
> using the for-statement and the range() function. But you can also
> combine iterating over elements
[EMAIL PROTECTED] wrote:
> AlbaClause wrote:
>
> > for i in range(length):
> > print i
>
> Or usually better:
>
> for ii in xrange(length):
~~
I hate ii ;)
Regards,
Kay
--
http://mail.python.org/mailman/listinfo/python-list
Putty wrote:
> In C and C++ and Java, the 'for' statement is a shortcut to make very
> concise loops. In python, 'for' iterates over elements in a sequence.
> Is there a way to do this in python that's more concise than 'while'?
>
> C:
> for(i=0; i
>
> python:
> while i < length:
>
AlbaClause wrote:
> for i in range(length):
> print i
Or usually better:
for ii in xrange(length):
...
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Putty wrote:
> In C and C++ and Java, the 'for' statement is a shortcut to make very
> concise loops. In python, 'for' iterates over elements in a sequence.
> Is there a way to do this in python that's more concise than 'while'?
>
> C:
> for(i=0; i
>
> python:
> while i < length:
> i += 1
for
18 matches
Mail list logo