Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to change this dictionary output?

Change my dictionary, this is the initial code:

bow=[[i for i in all_docs[j] if i not in stopwords] for j in range(n_docs)]
bow=list(filter(None,bow))
bow

Here is bow output:

[['lunar',
  'satellite',
  'needs'],
['glad',
  'see',
  'griffin'] ]
worddict_two = [ (i,key) for i,key in enumerate(bow)]
worddict_two

From this output :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 [(0,
  ['lunar',
   'satellite',
   'needs']),
  (1,
  ['glad',
   'see',
   'griffin'])

to this output:

 [(0,'lunar satellite needs'),
  (1,'glad see griffin') ) ]

>Solution :

worddict_two = [ (i, " ".join(key)) for i,key in enumerate(bow)]

This would work. Use join to Join all items in a tuple into a string with space space as a separator

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading