Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # encoding: utf-8
- from collections import defaultdict
- word2value = {'dog': 15, 'dogs': 20}
- word2stem = {'dog': 'dog', 'dogs': 'dog'}
- stem2value = defaultdict(int)
- for word, stem in word2stem.iteritems():
- stem2value[stem] += word2value[word]
- for word in word2value:
- word2value[word] = stem2value[ word2stem[word] ]
- print word2value
- # {'dog': 35, 'dogs': 35}
Add Comment
Please, Sign In to add comment