How smart is the Python interpreter?

ssecorp circularfunc at gmail.com
Thu Jul 31 13:09:57 CEST 2008


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?



More information about the Python-list mailing list