Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Name Groups

Topher Knoll
Topher Knoll
3,572 Points

Bummer: Hmm, no .groups() attribute. Did you do a match?

I'm not quite sure what this even means [as usual.] This vague bummer code doesn't make sense. The lesson teaches us to use .groupsdict() which is the root of the problem I guess. I don't remember there being anything about .groups(). Anyway, I use both on the names string and it gives me either this error or something about there not being a .groupsdict() method.

Stuck yet again.

names.py
import re

string = 'Perotto, Pier Giorgio'

names = re.match(r'''
    ^(?P<first>[\w ]+),\s
    (?P<last>[\w ]+)
''', string, re.X|re.M)

names = names.groupdict()

2 Answers

Steven Parker
Steven Parker
211,016 Points

The instructions only ask for the result of the "re.match" to be assigned to "name". The extra step is replacing what would otherwise be a correct result with one of it's attributes.

Topher Knoll
Topher Knoll
3,572 Points

Okay. I just removed the last line. Confusing directions... But, thanks!