I am trying to count the number of times a value shows up in a sorted list. I know I can just use the count method but why does the following code not work?
lst = []
a = ['polka dot sock\n', 'polka dot sock\n', 'polka dot sock\n', 'red sock\n', 'superhero shirt\n', 'torn jeans\n', 'white shirt\n', 'white shirt\n']
for x in a:
     c = 0
     while x in a:
          c += 1
          a.remove(x)
     lst.append((a, c)) 
print lst 
The code works for everything except 'red sock\n' and 'torn jeans\n'. Why is that? Is it an indexing issue?
 
     
    