def store(k, terms, shlf_path): main_shlv = shelve.open(shlf_path, 'c') for w in terms: if w in main_shlv: index = main_shlv[w] else: index = Index() index.add_doc(int(k)) main_shlv[w] = index main_shlv.close()