I want to update the keys of my dictionary c
with its new keys k_new
. Even though I am referring different stack overflow questions like this it does not get updated. Please tell me where I make it wrong.
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
c = {'apples': 3, 'biscuits and tea': 3, 'oranges and onions': 4}
for k in c:
splits=k.split()
k_new= " ".join(lemmatizer.lemmatize(w.lower()) for w in splits)
c[k_new] = c.pop(k)
print(c)
PS: I also used:
c[k_new] = c[k]
del c[k]
Then I get RuntimeError: dictionary changed size during iteration
Please help me