Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Schut
2,317 Pointsplayers.py
I don't get the order of the lastname and firstname right for "Stewart Pinchback" and "Pinckney Benton". I have no idea how to do this (because there 'format' is so different from the first 4 names).
import re
string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''
players = re.search(r'''
(?P<last_name>[\w]+),?\s?:?
(?P<first_name>[\w]+):?\s?
(?P<score>[\d]+)?
''', string, re.MULTILINE|re.I|re.X)
2 Answers
Steven Parker
231,269 PointsYou are sooooo close!
You just need to include a space with your word character classes ("[\w ]
") to allow the multi-word names to be accepted as a single name.
And while it's beyond what's necessary to pass the challenge, I'd probably not allow the separator characters or the score to be optional, and make sure the names start and end with a non-space word character
players = re.search(r'''
(?P<last_name>\w([\w ]*\w)?),\s*
(?P<first_name>\w([\w ]*\w)?):\s*
(?P<score>[\d]+)
''', string, re.MULTILINE|re.I|re.X)
John Schut
2,317 PointsHi Steven, I took a short break, therefor I answer this late. Thanks for your response! I am going to try it out now.