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.
我只需要它打印一次。此外,我想弄清楚如何把項目放在引號中。
'不帶參數str.split'按空白進行分割,而不是逗號。 – chepner