Python removing words from strings
Question: My desired program has to read a text file like this:

    
    
    EASTS versus WESTS
    EASTS have scored 25:13
    WESTS have scored 26:28
    WESTS have scored 40:23
    WESTS have scored 42:01
    

and run the following output:

    
    
    WESTS 3
    EASTS 1
    

I think i need to first put it into groups. Remove the newline characters.
Then remove everything but the capital letters in the first line and assign
them to seperate variables. Then search the text for the amount these
variables occur. so that would mean a = 2 and b = 4 then - 1 off each total
and have that as result. This is what i have so far:

    
    
    import string
    teams = []
    for word in open('commentary.txt'):
      word = word[:-1] # gets away the /n characters.
      word = word.strip("versus") # This line doesn't work
      teams.append(word)
    print(teams)
    

I think i know what to do but i dont know... Any help would be appreciated :D
Thanks


Answer: You need to use a dict or a counter for this. Something like this.

    
    
     from collections import Counter
     counter = Counter()
     for line in file:
         if 'versus' in line:
             continue
         words = line.split()
         counter[words[0]] += 1
    
     for team in counter:
         print team, counter[team]
    

