Unble to convert list of tuples to dictionary

Iam able to get the tuple and not able to convert into dictionary

for tag in list(tagged):

This is the output of tuple

    hi NN
    I PRP
    am VBP
    just RB
    testing VBG

It shows ValueError: not enough values to unpack (expected 2, got 1) when I execute this code

dicts={w:p for w,p in tag}

1 answer

  • answered 2018-03-14 20:03 YOLO

    This is to show what should be the structure of tagged so that it works. I tried with your code and it works. Just one change in creating a dict.

    tagged = [('hi', 'NN') , ('I', 'PRP'), ('am','VBP'), ('just','RB'), ('testing','VBG')]
    #for tag in list(tagged):
    #            w,p=tag
    #            print(w,p)
    {'I': 'PRP', 'am': 'VBP', 'hi': 'NN', 'just': 'RB', 'testing': 'VBG'}