Can I do this faster?

Alain TESIO alain at onesite.org
Wed Aug 9 15:39:45 EDT 2000


Hello,

I think there is no magical trick to speed it up with this structure.
You should create (and modify it when s.__rowDict is modified) a dictionary having
s.__rowDict[key]['data'] as a key.

It's similar to creating an index in a database (unique as you don't seem to worry about
diplicates) :

index={}
for key in s.__rowDict.keys():
	index[s.__rowDict[key]['data']]=key


When you have this index, this uses a hash and is immediate :

def __GetRowID (index, row):
	if index.has_key(row):
		return index[row]


Alain



On Wed, 09 Aug 2000 08:35:58 +0200, Horst Gassner <horst at proceryon.at> wrote:

>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
>
>Thanx in advance
>Horst




More information about the Python-list mailing list