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 Groups

Getting incorrect info in console at the end of video. Also - Bug for 'Get Help' on chrome version of website.

This is the code I have below. I have referenced Kenneth's code several times and caught 2 errors but can not for the life of me find the last one.

line = re.search(r'''
  ^(?P<name>[-\w ]*,\s[-\w ]+)\t
  (?P<email>[-\w\d.+]+@[-\w\d.]+)\t
  (?P<phone>\(?\d{3}\)?-?\s?\d{3}-\d{4})?\t
  (?P<job>[\w\s]+,\s[\w\s.]+)\t?
  (?P<twitter>@[\w\d]+)?$
''', data, re.X|re.M)

print(line)
print(line.groupdict())

Following is the result I get from the console after running my script:

<_sre.SRE_Match object; span=(0, 86), match='Love, Kenneth\tkenneth@teamtreehouse.com\t(555) 5>
{'name': 'Love, Kenneth', 'email': 'kenneth@teamtreehouse.com', 'phone': '(555) 555-5555', 'job': 'Teacher, Treehouse\t', 'twitter': '@kennethlove'}

From what I can tell, his result goes : Name, email, job, twitter, phone. And my result goes : Name, email, phone, job, twitter. My result is in the same order as the code, but his goes out of order and puts the phone category at the end.

Is there something I am missing which accounts for this mix up? Or is it an aspect of regex / dictionaries?

BUG - When clicking on 'Get Help' button on pages with videos, it starts playing or resumes the video. Very minor but still thought I would point it out for some "Whose line is it anyways?" type points.

1 Answer

Steven Parker
Steven Parker
210,863 Points

This is not an aspect of regex, but of dictionaries in general. Dictionaries are orderless collections, and the order items appear in the output is neither significant nor should it be relied on to remain consistent.

Your other observation sounds like a legitimate bug. You may want to report it directly to the staff as described on the Support page. I don't think it carries any points, but you may get the "special Exterminator badge". :beetle: