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 trialhugo dahl
2,967 Pointshow? answer pls
tr
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*\w*]+), \s(?P<first_name>[-\w\s*\w]+): \s(?P<score>[\d]+)$ ''',string, re.X | re.M)
1 Answer
Steven Parker
231,268 PointsYour code passes task 1 as-is, so I assume you're asking about task 2. The instructions ask you to "create a class named Player that has those same three attributes, last_name, first_name, and score.". But they could have been a bit more explicit about how they will be set. It turns out the challenge will pass them in as keyword arguments.
So, you can do this using a bit of standard Python boilerplate code (which is totally unrelated to regular expressions!):
class Player:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
hugo dahl
2,967 Pointshugo dahl
2,967 Pointsis this all the code needed or do i need to use this with the rest?
Steven Parker
231,268 PointsSteven Parker
231,268 PointsRemember that the instructions say "Important: In each task of this code challenge, the code you write should be added to the code from the previous task."