使用字典快速解决 str_n = input() dic = {} for i in str_n: if i == " ": continue key = i dic[key] = dic.get(key,0) + 1 for i in dic: print(i+":"+str(dic[i]))
使用字典快速解决 str_n = input() dic = {} for i in str_n: if i == " ": continue key = i dic[key] = dic.get(key,0) + 1 for i in dic: print(i+":"+str(dic[i]))