張芝瑜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)#將串列轉成集合,稱他mySet得到1251
myDict = dict()     #定義字典dict稱他為 myDict
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'字元數目{len(reading):,},不同字元數{len(mySet):,}')
#python和其他所有語言不同的特徵 f string格式化字串文字
print(f"張芝瑜統計左引號(出現次數{myDict['(']:,}")
print(f'張芝瑜統計右引號)出現次數{myDict[")"]:,}')
print(f'張芝瑜統計504每題四個選項至少有{504*4:,}')

留言

  1. 1113.商業軟體,Typescript,神力女超人!https://zzy317.blogspot.com/2026/11/typescriptjavascripttetris.html
    五角型計算機。https://zzy317.blogspot.com/2026/11/htmlcssjavascript.html
    商業軟體期中考。data資料...英文一定要正確。
    https://zzy317.blogspot.com/2026/10/excelandorcountcountifindirect.htmlhttps://zzy317.blogspot.com/2026/11/excelformulas.html
    https://zzy317.blogspot.com/2026/10/excelmatchindexisnumber.html
    程式設計期中考,完美!https://zzy317.blogspot.com/2026/11/htmlcssjavascriptpython.html
    https://zzy317.blogspot.com/2026/10/pythoninputfind-1.html
    https://zzy317.blogspot.com/2026/10/pythonsetdict372411251.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

張芝瑜w3schools字串str串列list集合set字典dict元組tuple

張芝瑜EXCEL名稱方塊,AND,OR,COUNT,COUNTIF,INDIRECT間接定址