[問題] 如何print出東西
以下為兩個函式
是要從txt讀檔進來
第一個原不是寫成函式,所以在open的filename打上"檔案名稱.txt"就可以output
第二個是計算每個字出現多少次的函式
def readbook(filename):
readin = open(filename)
count = []
for line in readin:
read = line.split()
count = count + read
return count
def list2dict(count):
ldict = dict()
for ch in count:
ldict[ch]=ldict.get(ch,0)+1
return ldict
想問要如何打print()裡面的內容才可以print出每個字出現幾次
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.14.36.3
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1397736866.A.BD2.html
推
04/17 22:34, , 1F
04/17 22:34, 1F
→
04/17 23:37, , 2F
04/17 23:37, 2F
→
04/19 02:10, , 3F
04/19 02:10, 3F
→
04/19 11:05, , 4F
04/19 11:05, 4F
→
04/19 11:06, , 5F
04/19 11:06, 5F
→
04/19 15:47, , 6F
04/19 15:47, 6F
→
04/24 17:42, , 7F
04/24 17:42, 7F
→
04/24 17:43, , 8F
04/24 17:43, 8F
→
04/24 17:49, , 9F
04/24 17:49, 9F
→
04/24 17:51, , 10F
04/24 17:51, 10F