簡體   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