+15 投票
分类:编码思路 | 用户: 9 4 3 (2.5k 分)
可行方案之一

#词频统计

freq = {}  

line = input()

for word in line.split(' '):

    freq[word] = freq.get(word,0)+1

words = sorted(freq.keys())

 

for w in words:

    print ("{word}:{frequence}".format(word=w,frequence=freq[w]))

2 个回答

0 投票
用户: 9 5 5 (1.4k 分)
str1=input('')

strs=sorted(str1.split(' '))

dic={}

strs1=strs

for str in strs:

    if str not in dic.keys():

        dic[str]=1

    else:

        dic[str]+=1

for key,value in dic.items():

    print('{}:{}'.format(key,value))
用户: 9 5 5 (1.4k 分)
第四行删掉
0 投票
用户: 5 1 (530 分)
message=input()
list=message.split(' ')
list.sort()
dictionary={}
for l in list:
    if l not in dictionary:
        dictionary[l]=1
    else:
        dictionary[l]=dictionary[l]+1
for k,y in dictionary.items():
    print(k,end=':')
    print(y)
欢迎来到 在线问答系统 ,有什么不懂的可以尽管在这里提问,你将会收到社区其他成员的回答。
...