my_list=raw_input('Please enter a list of items (separated by comma): ')
my_list=my_list.split()
my_list.sort()
print "List statistics: "
for x in my_list:
z=my_list.count(x)
if z>1:
print x, "is repeated", z, "time."
else:
print x, "is repeated", z, "times."
我试图让程序按字母顺序对列表进行排序,然后打印它找到的每个列表的数量。输出是:
List statistics:
bird, is repeated 1 time.
cat, is repeated 1 time.
dog is repeated 1 time.
dog, is repeated 2 times.
dog, is repeated 2 times.
我只需要它每次打印一次。另外,我想弄清楚如何将项目放在引号中。