Can I do this faster?

Olaf Delgado delgado at olaf.de
Wed Aug 9 14:40:07 EDT 2000


Horst Gassner <horst at proceryon.at> writes:
> Hello!
> 
> The following code is executed very often in my program and I would be
> happy if someone could help me to speed this up.
> 
> def __GetRowID (s, row):
> 	for key in s.__rowDict.keys():
> 		if s.__rowDict[key]['data'] == row:
> 			return key

I imagine the following might be slightly faster:

def __GetRowID (s, row):
	for key, val in s.__rowDict.items():
		if val['data'] == row:
			return key

Some kind of caching would help a lot more, I guess.

-- 
  ////
  Olaf  Delgado Friedrichs, Bielefeld, Germany
  `='   --- http://www.mathematik.uni-bielefeld.de/~delgado ---



More information about the Python-list mailing list