iterating through humongously large key lists!!

Mark blobby Robinson m.1.robinson at herts.ac.uk
Wed Apr 25 13:18:54 EDT 2001


I needed a non-destructive method so popitem was not a viable option, but I
was able to use juans suggestion of using the firstkey() and nextkey()
methods but with gdb. However although I can iterate through the list
beautifully now I am getting some wierd behaviour which is throwing me. If I
run the following code:

x = db.firstkey()
while x != None:
             if db[x] < 2:
                        del db[x]
             x = db.nextkey[x]


I get the following exception:

Traceback (innermost last):
  File "test.py", line 28, in ?
    findEligible(filename+'.dat', Dict)
  File "motif.py", line 252, in findEligible
    del motiflist[x]
  File "/usr/lib/python1.5/shelve.py", line 74, in __delitem__
    del self.dict[key]
KeyError: CACTG_GCGCC_TATAG

Which seems wierd to me, the key is obviously there cos I have just extracted
it using firstkey() and nextkey(). Just to check instead of the line:    del
db[x]     I tried     print db[x]
and that doesn't generate a keyError. Why should del db[x] give me a
keyError?

Blobby




More information about the Python-list mailing list