Newbie Question: Sort Tip: Why n=n?

Vaughn H. Seward vaughn at sewardSBLOKconsulting.comMAND.invalid
Thu Jan 17 22:16:45 EST 2002


In "Python Performance Tips", Guido van Rossum has a little tip on
sorting:

http://manatee.mojam.com/~skip/python/fastpython.html#sorting
 
He suggests the following:
 
def sortby(list, n):    
    nlist = map(lambda x, n=n: (x[n], x), list)
    nlist.sort()    
    return map(lambda (key, x): x, nlist)
 
I understand everything about this except the n=n in the second line.
Does anyone know why this is required?
 
~Vaughn Seward



More information about the Python-list mailing list