I'm trying to create a bigram from a dictionary with a specific condition. Below is the example of the dictionary:
dict_example = {'keywords1': ['africa',
'basic service',
'class',
'develop country',
'disadvantage',
'economic resource',
'social protection system']
The specific condition is that I want to create a bigram if the words in each element are more than 1. Below is the code that I have been working on so far:
keywords_bigram_temp = {}
keywords_bigram = {}
for k, v in dict_example.items():
keywords_bigram_temp.update({k: [word_tokenize(w) for w in v]})
for k2, v2 in keywords_bigram_temp.items():
keywords_bigram.update({k2: [list(nltk.bigrams(v3)) for v3 in v2 if len(v3) > 1]})
This code works, but instead of returning a normal tuple within a list (I think this is what bigram normally looked like), it returns a tuple within a nested list. Below is an example of the result:
'keywords1': [[('basic', 'service')],
[('develop', 'country')],
[('economic', 'resource')],
[('social', 'protection'),
('social', 'system'),
('protection', 'system'),
('social', 'protection')]}
What I need is a normal bigram structure, a tuple within a list like so:
'keywords1': [('basic', 'service'),
('develop', 'country'),
('economic', 'resource'),
('social', 'protection'),
('protection', 'system')]}