徐梓寧python集合set字典dict統計字元數目37241不同字數1251

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'字元數目{len(reading):,},不同字元數{len(mySet):,}')
#pythi=on和其他所有語言不同的特徵 f string格式化字串文字
print(f"徐梓寧統計左引號(出現次數{myDict['(']:,}")
print(f'徐梓寧統計右引號(出現次數{myDict[")"]:,}')
print(f'徐梓寧統計504每題四個選項至少有{504*4:,}')

留言

  1. 商業軟體期中考,必須訂正,要呈現正確資訊。https://tzuning-hsu.blogspot.com/2026/11/excelformulas.html
    計算機。https://tzuning-hsu.blogspot.com/2026/11/htmlcssjavascrip.html
    程式設計期中考。https://tzuning-hsu.blogspot.com/2026/11/htmlcssjavascriptpython.html
    https://tzuning-hsu.blogspot.com/2026/10/pythoninputfind-1.html
    https://tzuning-hsu.blogspot.com/2026/10/pythonsetdict372411251.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

徐梓寧python輸入input尋找find沒找到-1