with better check with unique number. I think its not a good idea using enumerate function. Since enumearte repeates the number once new directory of files/ data in called.
I use anydbm alot and i think the best way is to use a counter with a dict. Then you check with the last dict call incrementing by 1 and use that for next key.
import anydbm
ddf = anydbm.open("ns.cdx",'r')
unique = len(ddf.keys())
db = anydbm.open("ns.cdx",'c')
for x in range(300):
for y in reversed(range(1,4)):
db[str(unique)] = str(y)
unique = int(unique)
unique += 1
print("Key | Values \n ")
print "="*50
for x in ddf.keys():
print x ,":", ddf[x]
db.close()
ddf.close()
from my htc phone. hope you get my idea ;)