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 trialDaniel Petrov
3,495 PointsSame results
Skipping the second and fourth lines brings the same results. Why would we use them? @Keneth Love
Daniel Petrov
3,495 PointsThanks Steven
3 Answers
Kenneth Love
Treehouse Guest TeacherHmm, OK. That's totally possible! But why have those lines? Well, partly for explicitness (especially line 3) and partly for clean data (line 5).
If, somehow, I had a string like hello-there,what-is-happening
, I wouldn't necessarily want it to match. The regex would prevent that because there's no whitespace after the comma. Also, if a line does end with a tab or newline, I don't want that tab or newline to be included in my results because they're not useful characters.
Daniel Petrov
3,495 PointsYes, that makes sense! Thanks!
Kenneth Love
Treehouse Guest TeacherI'm not sure exactly what you mean by "second and fourth lines". Can you show me an example?
Daniel Petrov
3,495 PointsSorry my bad, it is actually 3 and 5. I am getting the same result with and without these two lines.
print(re.findall(re'''
\b[-\w]+,
\s <---
[-\w ]+
[^\t\n] <---
''', data, re.X))
Steven Parker
231,248 PointsSteven Parker
231,248 PointsIt doesn't look like your tag for Kenneth Love was correctly converted into a link. This one should work.
And I don't know which "lines" you are referring to, but perhaps he will.