Can I do this faster?
Niklas Frykholm
r2d2 at mao.acc.umu.se
Wed Aug 9 04:46:22 EDT 2000
In article <3990FBCE.ED3458D8 at proceryon.at>, Horst Gassner wrote:
>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
Is the data in the rows static? In that case I would create an inverse
lookup table
def __CreateLookupTable(s):
s.__lookup = {}
for key in s.__rowDict.keys():
s.__lookup[s.__rowDict[key]['data']] = key
Run this once somewhere in your program. Now you can do
def __GetRowID (s,row):
return s.__lookup[row]
// Niklas
More information about the Python-list
mailing list