This is my code.I am getting error in this code line.
inverse_vocabulary = dict.get((word, i) for i, word in enumerate(vocabulary))
My error is:
TypeError Traceback (most recent call last)
> <ipython-input-27-7941d5453736> in <module>()
> 21
> 22 vocabulary = open(r"G:\final year
> project\data/vocabulary.txt").read().split("\n")
> ---> 23 inverse_vocabulary = dict.get((word, i) for i, word in
> enumerate(vocabulary))
> 24
> 25 TypeError: descriptor 'get' requires a 'dict' object but
received a
> 'generator'
First, dumb detail, but Python is not a compiled language - it is an interpreted language - just for your own future reference
Second, as the commentor said - you're passing a generator into dict.get(). Wrap that generator in a dict() call to evaluate it to a dictionary.
inverse_vocabulary = dict.get(dict((word, i) for i, word in enumerate(vocabulary)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.