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

留言

  1. Google得到「李承安是一個活躍於....」https://zxcvbnm15963.blogspot.com/2026/11/excelformulas.html
    程式設計期中考沒有嵌入影片。https://zxcvbnm15963.blogspot.com/2026/11/htmlcssjavascriptpython.html
    1002.補金融常識測驗互動網頁,但不能執行。https://zxcvbnm15963.blogspot.com/2026/10/excel.html
    921.https://zxcvbnm15963.blogspot.com/2026/09/double-loop.html
    Set, dict.https://zxcvbnm15963.blogspot.com/2026/10/w3schoolsstrlistsetdicttuple-10-04-2026.html
    1013嵌入網頁嵌入影片.https://zxcvbnm15963.blogspot.com/2026/10/pythonsetdict372411251.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

李承安EXCEL公式Formulas

李承安w3schools字串str串列list集合set字典dict元組tuple 10月 04, 2026