Python Sorting Regular Expression
Question: Hi making a file that sorts through a txt file and selects the name: and the
first 3 stats and stores them in a dict then does the same for the next name +
3 stats if dict isn't smart storing them in a list would work also I think.

## the txt file looks like this:

    
    
    player a 34 45 56 player b 38 93 75 playerc 39 29 18 playerd 38 98 
    

I tried `player = re.findall(r"[-+]?\d*\.\d+|\d+", player_string)` But it only
gives me the player ratings and I think I need to use some kind of dict to
store all the different players.

If this is complicated you don't have to do the entire thing for me just point
me in the right direction. Thank you. I'm using py2.6


Answer: I think what you need is:

    
    
    import re
    
    player_string = "player a 34 45 56 player b 38 93 75 playerc 39 29 18 playerd 38 98"
    
    pattern = re.compile(r"player\s+(\w+)\s+(\d+)\s+(\d+)\s+(\d+)")
    matches = pattern.findall(player_string)
    d = {}
    for m in matches :
        print m
        d[m[0]] = m[1:]
    
    print d
    

Pay attention that you wrote "playerc" and "playerd" without spaces and these
2 will not be found.

