Im trying to create a function that takes a list of tokenized words for a review and a label and returns a list of tuples composed of a python dictionary and the label associated.
You can see what I mean more clearly by what the output is supposed to look like below.
Heres the code that I have:
<code>def featureExtraction(clean_tokenized, label):
features = []
for line in clean_tokenized:
for word in line:
d = dict({word: True})
d1 = (d, label)
tup.append(d1)
return features
</code>
<code>def featureExtraction(clean_tokenized, label):
features = []
for line in clean_tokenized:
for word in line:
d = dict({word: True})
d1 = (d, label)
tup.append(d1)
return features
</code>
def featureExtraction(clean_tokenized, label):
features = []
for line in clean_tokenized:
for word in line:
d = dict({word: True})
d1 = (d, label)
tup.append(d1)
return features
Example Input:
<code>[['hate', 'movie'],
['acting', 'terrible']]
</code>
<code>[['hate', 'movie'],
['acting', 'terrible']]
</code>
[['hate', 'movie'],
['acting', 'terrible']]
Expected output:
<code>[
({'hate': True, 'movie': True}, 'neg')
({'acting': True, 'terrible': True}, 'neg')
]
</code>
<code>[
({'hate': True, 'movie': True}, 'neg')
({'acting': True, 'terrible': True}, 'neg')
]
</code>
[
({'hate': True, 'movie': True}, 'neg')
({'acting': True, 'terrible': True}, 'neg')
]
This is what my code is producing:
<code>[({'hate': True}, 'pos'), ({'movie': True}, 'pos'), ({'acting': True}, 'pos'), ({'terrible': True}, 'pos')]
</code>
<code>[({'hate': True}, 'pos'), ({'movie': True}, 'pos'), ({'acting': True}, 'pos'), ({'terrible': True}, 'pos')]
</code>
[({'hate': True}, 'pos'), ({'movie': True}, 'pos'), ({'acting': True}, 'pos'), ({'terrible': True}, 'pos')]
I would love some assistance with this. Thank you!
New contributor
Kevin Veeder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.