Is shelve really slow and taking a lot of memory or am I doing something wrong?

放肆的年华 提交于 2019-12-06 03:32:23

First -- yes, shelve's default pickle backend is slow and inefficient, and your best choice is to use something different.

Second -- you're making it worse by editing entries once they're there, rather than getting them into their final state in-memory before serializing them only once.

dct = anagrams_from_list(process_file(filename))
for key, wordlist in dct.items():
  content = {}
  for key, wordlist in dct.iteritems():
    if not key in content:
      content[key] = wordlist
    else:
      content[key].extend(wordlist)

for k, v in content.iteritems():
  db[k] = v

If you want an efficient database, I'd look elsewhere. tokyocabinet, kyotocabinet, SQLite, BDB; the options are numerous.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!