Python / C: small runtime difference?

Alan Gauld alan.gauld at
Tue Sep 9 19:12:43 CEST 2003

On Tue, 9 Sep 2003 15:54:41 +0200, "Martin Schneider"
<martin.schneider at> wrote:

> for i in range(len(fileList)-1):
>  for j in range(len(fileList)-i-1):
>   if fileList[j+1] < fileList[j]:
>    tmp = fileList[j]
>    fileList[j] = fileList[j+1]
>    fileList[j+1] = tmp

I think you might tweak that by doing:

fileList[j],fileList[j+1] = fileList[j+1],fileList[j]

which misses out the intermediate tmp assignment.
If you are gonna tweak the C you might as well tweak the 
Python too! (But not with a real python, they tweak back 
hard! :-)

Alan G.
Author of the Learn to Program website

More information about the Python-list mailing list