李宜萱python集合set字典dict統計字元數目37,241不同字元數1,251

file = open('金融常識.txt','r',encoding='utf-8')
reading = file.read()
file.close()
print('檔案字元characters數:', len(reading))
mySet = set(reading)
myDict = dict()
for j in mySet:
    myDict[j] = 0
for i in reading:
    myDict[i] += 1
for j in mySet:
    print(f"字元「{j}」出現{myDict[j]:,}次數")
print(f"李宜萱統計左引號(出現次數{myDict['(']}")
print(f'李宜萱統計右引號)出現次數{myDict[')']}')
print(f'李宜萱統計504每題四個選項至少有{504*4}')

留言

  1. CSS階層式樣式表的H1沒有用/H1結束導致錯誤!https://glacier0831.blogspot.com/2026/11/htmlcssjavascriptpython.html
    http://glacier0831.blogspot.com/2026/10/excelandorcountcountifindirect.html
    1113.Typescript俄羅斯方塊。https://glacier0831.blogspot.com/2026/11/typescriptjavascripttetris.html
    計算機。https://glacier0831.blogspot.com/2026/11/html-css-javascript.html
    商業軟體期中考。https://glacier0831.blogspot.com/2026/11/excelformulas.html
    https://glacier0831.blogspot.com/2026/10/pythoninputfind-1.html
    https://glacier0831.blogspot.com/2026/10/excelmatchindexisnumber.html
    https://glacier0831.blogspot.com/2026/10/pythonsetdict372411251.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

李宜萱excel字串處理產生金融市場常識