Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Players Dictionary and Class

Can't tell what they're asking for here - seems like two different things but I could be wrong

Any help with this question is appreciated. Thanks.

players.py
import re

string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''

players = re.compile(r"(?P<last_name>\w+),\s(?P<first_name>\w+):?\s?(?P<score>\d*)?", re.M)

1 Answer

Stuart Wright
Stuart Wright
41,101 Points

The format of your solution should look something like this:

players = re.match(r"your regex pattern in here", string, re.M)

Your version was using re.compile instead of re.match, and you didn't pass the string you want to search.

Once you change your solution to match the format posted above, you'll at least start getting some helpful error messages (your regex pattern isn't quite correct, but it's not far off). I pasted in your pattern as a starting point, then was able to solve it using the error messages to point me in the right direction, so I think it would be worth you trying the same. Let me know if you need any other hints.