繁体   English   中英

如何使用乌龟模块绘制直方图?

[英]How can I draw histogram using turtle module?

import first

counts = dict()

with open('junior.txt') as handle:
    for line in handle:
        words = line.split()
        for word in words:
            counts[word] = counts.get(word, 0) + 1

    print(counts)

bigcount = None
bigword = None

for word, count in counts.items():
    if bigcount is None or count > bigcount:
        bigword = word
        bigcount = count

first.show_histogram( vk_list )

这是我编写的用于计算单词出现频率的代码,在第一行中,有一个“ import first”(首先导入):首先是我要使用turtle的模块。 可以说,我想在这里计算频率,然后使用“第一”模块使用乌龟模块绘制直方图。 反映频率的直方图! 希望其他人理解它...无论如何,要执行此操作,我必须在first.py中使用该变量“ bigword”,但我不知道如何连接这两个文件。

例如,如果您的first.py包含一个名为b的变量,则可以从“主”文件中调用它,如下所示:

import first
bigword = first.b

反之亦然。 因此,从您的first.py文件中,您可以调用:

import [filename-containing-bigword]
bigword = [filename-containing-bigword].bigword

暂无
暂无

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

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