sort(): Giving third argument?
Piet van Oostrum
piet at cs.uu.nl
Sun Mar 23 07:33:14 EST 2003
>>>>> Thomas Guettler <zopestoller at thomas-guettler.de> (TG) wrote:
TG> Hi!
TG> If I have a list of IDs and a hash which maps
TG> each ID to a name:
TG> ids=[1, 2, 3, 4]
TG> names={
TG> 1: "foo",
TG> 2: "bar",
TG> ...}
TG> I can't do the following:
TG> def mycmp(a, b):
TG> return cmp(names[a], names[b])
TG> ids.sort(mycmp)
TG> since "name" is unkown in mycmp.
It isn't unknown. It is just a global variable and your code works with me.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl
More information about the Python-list
mailing list