解题思路:1.while循环判断n的值是否为0 2.for循环输入颜色的值,将其存入列表中 3.用count()函数计数,并且将列表值和计数值放进字典中 4.对字典进行排序,按照要求找到需要的出现最多次数的颜色,输出
注意事项:dic1=sorted(dic.items(),key=lambda x:x[1])这段代码排序过后是列表存着元组的结构,要搞清楚类型(type()判断)
参考代码:
n=int(input())
while n!=0:
list1=[]
dic={}
for i in range(n):
list1.append(input())
for i in list1:
if i not in dic:
dic[i]=list1.count(i)
dic1=sorted(dic.items(),key=lambda x:x[1])
print(dic1[-1][0])
n=int(input())
0.0分
0 人评分