0
我想要做的是比較每個字的第一個字母與 小寫字母az和字母打印(類似於word_frequency)多少個 次字用拼音 的每個字母(如本)開始無法獲得計數器來比較第一個字母的字母AZ字母表
a = 0 b = 2, c = 0, d = 2 ------------ y = 1, z = 0
但我無法找到一種方法,通過計數器來做到這一點作爲尚未或發現任何東西,對我來說(初級)工作。我的想法是沿線
for w in word_count:
l_freq = []
l_freq.append(w[0])
然後比較反對它呢?但不知道如何與整個字母表比較,而不僅僅是字符串中的字母?
此外,有沒有什麼方法可以打印頻率清潔器?沒有櫃檯和括號出現?
from collections import Counter
def function():
string = "This is a string written in python."
word_count = string.split()
char_count = 0
for char in string:
if char != " " and char != ".":
char_count += 1
word_freq = Counter(word_count)
print "Word count: " + str(len(word_count))
print "Average length of word: " + str(char_count/len(word_count))
print ""
print "Word frequency: "
print word_freq
謝謝你的快速反應如此之多現在就會嘗試,如果它的工作將立即標記爲解決方案! – LiamSutton