AttributeError: ‘dict‘ object has no attribute ‘t‘

AttributeError: ‘dict‘ object has no attribute ‘t‘_第1张图片

修改第五行代码

names=input("请输入各个同学行业名称,行业名称之间用空格间隔(回车结束输入):")
t = names.split()
d = {}
for c in range(len(t)):
    d[t[c]] = d.get(t[c],0) +1
    ls = list(d.items())
ls.sort(key=lambda x:x[1], reverse=True) # 按照数量排序
for k in ls:
    print("{}:{}".format(k[0],k[1]))

你可能感兴趣的:(python报错处理,python)