标签:count ssl ssd read split file close sum ext
#1. SummertimeSadnessFile = open(‘SummertimeSadness.txt‘,mode="r",encoding=‘utf-8‘) SummertimeSadnessText = SummertimeSadnessFile.read() SummertimeSadnessFile.close() print(SummertimeSadnessText) #2. replaceList = [‘,‘,‘.‘,"‘",‘\n‘] for c in replaceList: SummertimeSadnessText = SummertimeSadnessText.replace(c,‘ ‘) print(SummertimeSadnessText) #3. print(SummertimeSadnessText.split(‘ ‘)) SummertimeSadnessList = SummertimeSadnessText.split(‘ ‘) #4. SummertimeSadnessSet = set(SummertimeSadnessList) print(SummertimeSadnessSet) SummertimeSadnessDict = {} for word in SummertimeSadnessSet: SummertimeSadnessDict[word] = SummertimeSadnessList.count(word) print(SummertimeSadnessDict) for d in SummertimeSadnessDict: print(d,SummertimeSadnessDict[d])
标签:count ssl ssd read split file close sum ext
原文地址:https://www.cnblogs.com/csn123/p/9206175.html