Re: How smart is the Python interpreter?
- From: "Diez B. Roggisch" <deets@xxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 13:57:28 +0200
ssecorp wrote:
def str_sort(string):
s = ""
for a in sorted(string):
s+=a
return s
if i instead do:
def str_sort(string):
s = ""
so = sorted(string)
for a in so:
s+=a
return s
will that be faster or the interpreter can figure out that it only has
to do sorted(string) once? or that kind of cleverness is usually
reserved for compilers and not interpreters?
There isn't much cleverness involved here - why on earth should one execute
the sorted(string) several times?
The
for <name> in <iterable_yielding_expression>
construct will evaluate the <iterable_yielding_expression> of course only
once.
Diez
.
- References:
- How smart is the Python interpreter?
- From: ssecorp
- How smart is the Python interpreter?
- Prev by Date: Re: How smart is the Python interpreter?
- Next by Date: Re: Continuous integration for Python projects
- Previous by thread: Re: How smart is the Python interpreter?
- Next by thread: Re: How smart is the Python interpreter?
- Index(es):
Relevant Pages
|