weixin_39779004的博客方法一:sentence = "I can because i think i can"result= {word: sentence.split().count(word) for word in set(sentence.split())}print(result)方法二:defcount(str):count_words=str.split()count_word={}for...
Wwmy7_的博客str1=input('请输入一段字符:') dict1={} ...for i in str1.lower(): #使字符串全部变为小写,并遍历 if 'a'<=i<='z': dict1[i]=str1.count(i) #字典的添加 for key,value in dict1.items():...
阿肆5的博客给定字符串,输出每个字母出现的次数 def count_char(string): dict = {} for i in string: if i not in dict: dict[i]=1 else: dict[i]+=1 return dict print(count_char('skdaskerkjsalkj'))