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 trialElizabeth McInerney
3,175 PointsI am stuck on getting the contents of a group named email from my match object. I tried match_object.groupdict(email)
No more details, I just can't figure this one out. I don't recall this from the group video.
4 Answers
Elizabeth McInerney
3,175 PointsI just tried this and it failed, but I could not read why because it still gave me credit for the quiz and the big box announcing my credit obscured the reason. Just FYI
Kenneth Love
Treehouse Guest Teacher.groupdict()
gives you back a dict. To get the group (key) from it, you'd need to access the key of the returned dict, so .groupdict()['email']
.
Neil Gordon
8,823 Pointsthank youKenneth Love for the explanation
ahmed salah
9,195 Pointsmatch_obj.group('group_name')
Elizabeth McInerney
3,175 PointsThanks, that worked. I guess I just don't remember the group() method. Was it used recently?
Kenneth Love
Treehouse Guest TeacherWe went over the group()
method, yes. We didn't use it a lot because, usually, the groupdict()
is more useful. Sometimes, though, my quizzes and code challenges are going to require you to look things up in the documentation or experiment in your code or the Python shell to find the right answer. Research is probably the most useful tool a programmer has.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherAh, I see the question you're talking about.
This doesn't require
groupdict()
because we don't want a dict of the groups, we want just the content of a single group. We use the.group()
method and pass it the name of the group we want. So the answer isgroup('email')
(since the.
is already in the prompt).