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 trialmykolash
12,955 PointsCannot get into regexp for Python last challenge task
Cannot understand what is being asked from me here - not how2do, but what2do:
Task 2
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.
Can smbd explain it in other words, pls? Looking forward for smbd's help and thanx anyway?
PS: It's the last task for my Treehouse Python RegExp study - success was that close... but I've stuct :-(
import re
string = '''Love, Kenneth: 20
Chalkley, Andrew: 25
McFarland, Dave: 10
Kesten, Joy: 22
Stewart Pinchback, Pinckney Benton: 18'''
players = re.match(r'''
(?P<last_name>^[-\w ]*)
([,])
([\s])
(?P<first_name>[-\w ]+)
([:])
([\s])
(?P<score>\d{2}$)
''', string, re.X|re.M)
# While trying to solve the issue initialized this class with dict{<last_name>, <first_name>, <score>}.
# But still have no any idea what does it want from me :-(
p_dict = players.groupdict()
class Player:
self.last_name
self.first_name
self.score
def __init__(self, p_dict):
self.last_name = p_dict['last_name']
self.first_name = p_dict['first_name']
self.score = p_dict['score']
p = Player(p_dict)
print('class:')
print('p.first_name:', p.first_name)
print('p.last_name:', p.last_name)
print('p.score:', p.score)