Dictionary cloud generation for list items in python

 my_list=["one", "one two", "three"]

and I create a word cloud for this list using

 wordcloud = WordCloud(width = 1000, height = 500).generate(" ".join(my_list))

Since I convert all the elements to a string, it generates a word cloud for

   "one","two","three"

 But I want to generate word cloud for the values, "one","one two","three"

Help me create a word cloud for items in a list

+4
source share
1 answer

WordCloudtakes a regular expression as an argument. Using this, we can make the separator character a +instead of a space.

regexp=r"\w[\w' ]+"

Then the list of words should be attached to +, and each of them is now used to separate words. Result in the following code:

wordcloud = WordCloud(width=1000, height=500, regexp=r"\w[\w' ]+").generate("+".join(my_list))
+1
source

Source: https://habr.com/ru/post/1683334/


All Articles