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."
I am trying to get the program to sort the list alphabetically, then print how many of each it found. The output is:
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.
I only need it to print one time each. Also, I am trying to figure out how to put the item in quotation marks.
str.splitwith no argument splits on whitespace, not commas.