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

Anton Pugelj
Anton Pugelj
2,349 Points

Players dictionary and class challenge task 2 of 2 instructions? What are requested parameters for function __init__?

I can't guess what exactly is requested? Task request: Wow! OK, now, create a class named Player that has those same three attributes, last_name, first_name, and score. I should be able to set them through init.

players.py
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<first_name>\w+ *\w*), (?P<last_name>\w+ *\w*): (?P<score>\d+)',string,re.M)
class Player: 
    pat=re.compile(r'(?P<first_name>\w+ *\w*), (?P<last_name>\w+ *\w*): (?P<score>\d+)',re.M)

1 Answer

Task 2 has nothing to do with regular expressions. You're merely creating a Player class object.

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<first_name>\w+ *\w*), (?P<last_name>\w+ *\w*): (?P<score>\d+)',
    string, re.M)

class Player: 
    def __init__(self, first_name, last_name, score):
        self.first_name = first_name
        self.last_name = last_name
        self.score = score
Anton Pugelj
Anton Pugelj
2,349 Points

It was just to easy... Thanks for help.