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 trial

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

creating a class named player

Kind of lost here.

I was able to get the re.search(...) to work fine. Then the next step is to create a class and set the initial values to the same three groups.

when I attempt to have them set I get first_name has multiple values

Here is a copy of my code so far

class Player:
  def __init__(players):
    first_name = players.group('first_name')
    last_name = players.group('last_name')
    score = players.group('score')

Any help would be greatly appreciated. I think my biggest issue is I don't know how the values are being passed in to the class.

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Jeremy, I believe you overthink this problem, the solution is actually pretty simple.

class Player:
  def __init__(self, last_name, first_name, score):
    self.last_name = last_name
    self.first_name = first_name
    self.score = score

That worked. I think I need to study up on the classes a little bit. Thanks for the help.