張哲瑋python集合set字典dict統計字元數目37,241不同字元數1,251 10月 11, 2026

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例如改成DoraSet 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. 1019.要使用pre才能清楚呈現。https://jhangjhe-wei.blogspot.com/2026/10/ile-open.html
    https://jhangjhe-wei.blogspot.com/2026/10/blog-post.html
    這個會讓人覺得你只是應付了事。https://jhangjhe-wei.blogspot.com/2026/10/pythonsetdict372411251-10-11-2026_0254645609.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

張哲瑋Python撰寫金融常識測驗網頁