List: Counting and Deleting
Question: Given a list, for example List=["X","X","O","O",'O','O'], how would I count
how many "X"'s there are in a list, and then subtract that many "O"s from the
list. The List will always put all X's first and all O's last. I thought I
could do something like...

    
    
    List=["X","X","O","O",'O','O']
    ListCount=List.count("X")
    del List[-(List2):0]
    

I thought this would yield ["X","X","O","O"] by deleting the O's from -2:0 but
absolutely nothing happened. In python.


Answer: As noted in my comment, another data structure could be more useful here, as
you don't care about order:

    
    
    data = {"X": 2, "O": 4}
    data["O"] -= data["X"]
    

If you ever need the actual list, it's easy to create with a quick [generator
expression](http://www.youtube.com/watch?v=pShL9DCSIUw):

    
    
    from itertools import chain, repeat
    data_list = list(chain.from_iterable(repeat(key, count) for key, count in data.items()))
    

Or, to go the other way:

    
    
    from collections import Counter
    data = Counter(data_list)
    

