简体   繁体   English

从词典列表中删除几个词云

[英]Making several wordclouds out of list of dictionaries

I have a list of dictionaries in union_dicts . 我在union_dicts有一个字典列表。 To give you an idea it's structured as follows 为了给您一个想法,它的结构如下

union_dicts = [{'bla' : 6, 'blub': 9}, {'lub': 20, 'pul':12}]

(The actual lists of dicts is many times longer, but this is to give the idea) (词典的实际列表要长很多倍,但这是为了给出主意)

For this particular list of dictionaries I want to make a wordcloud. 对于这个特定的词典列表,我想制作一个词云。 The function that makes a wordcloud is as follows (nothing wrong with this one): 构成wordcloud的功能如下(此功能没有问题):

def make_words(words):
    return ' '.join([('<font size="%d">%s</font>'%(min(1+words[x]*5/max(words.values()), 5), x)) for x  in words])

Now I have written the following code that should give every dictionary back. 现在,我编写了以下代码,应该可以将每本字典还给我。 Return gives only the first dictionary back in the following function below: Return仅在下面的以下函数中返回第一个字典:

def bupol():
    for element in union_dicts: 
        return HTML(make_words(element))
bupol()

I have already tried to simply print it out, but then I simply get ''Ipython display object'' and not the actual display. 我已经尝试过简单地将其打印出来,但是然后我只是得到了“ Ipython显示对象”而不是实际的显示。 I do want the display. 我确实想要显示。 Yield also doesn't work on this function and for some reason using list = [] along with list.apped() return list instead of returning in the current way also doesn't work. Yield在此函数上也不起作用,由于某些原因,使用list = []以及list.apped()返回list而不是以当前方式返回也不起作用。 I'm quite clueless as how to properly iterate over this so I get a display of every single dictionary inside union_dicts which is a list of dictionaries. 对于如何正确地对此进行迭代,我一无所知,因此我可以看到在union_dicts内的每个字典的列表,该字典是一个字典列表。

How about something like this? 这样的事情怎么样?

def bupol():
    result = []
    for element in union_dicts: 
        result.append(HTML(make_words(element)))
    return result

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM