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 trialmichaelangelo owildeberry
18,173 PointsCreate a function named find_emails that takes a string. Return a list of all of the email addresses in the string.
Create a function named find_emails that takes a string. Return a list of all of the email addresses in the string.
multiple repeats, how is this happening? please help =)
import re
def find_emails(str):
return re.findall(r'\b[trehous]+{9}\b', str)
# Example:
# >>> find_email("kenneth.love@teamtreehouse.com, @support, ryan@teamtreehouse.com, test+case@example.co.uk")
# ['kenneth@teamtreehouse.com', 'ryan@teamtreehouse.com', 'test@example.co.uk']
8 Answers
Grzegorz Gancarczyk
10,064 PointsThis challenge will pass with this code: (something very similar to what MUZ140953 wrote but I promise I hadn't looked on this when I was writing my code :) )
def find_emails(string):
re_string = re.findall(r'[-\w\d+.]+@[-\w\d.]+', string)
return re_string
Just don't try to add these addresses to a new list and return it as I was trying to :)
Kenneth Love
Treehouse Guest TeacherWhy are you only searching for the letters "trehous" (occurring as a group of 9 characters) instead of searching for email addresses?
MUZ140953 Herbert Samuriwo
7,929 Pointsdef find_emails(str): return re.findall(r'[-\w\d+.]+@[-\w\d.]+', str)
thus how i had make it try this one
Abdillah Hasny
Courses Plus Student 3,886 Pointsdef find_emails(data):
result = re.findall(r'\w*.?\w+@\w+.\w+.?\w+',data)
return result
lol my regex just playing with *,+,?,\w not yet learn about [] and dot(.) in regex
Annie Scott
27,613 PointsAnswer
import re
Example:
>>> find_email("kenneth.love@teamtreehouse.com, @support, ryan@teamtreehouse.com, test+case@example.co.uk")
['kenneth@teamtreehouse.com', 'ryan@teamtreehouse.com', 'test@example.co.uk']
def find_emails(str): return re.findall(r'[-\w\d+.]+@[-\w\d.]+', str)
michaelangelo owildeberry
18,173 Pointsimport re
def find_emails(str):
return re.findall(r'\b[@]+{1}\b', str)
... my logic was that the any email must have the word treehouse... new logic says that any email has to have the at symbol... why does my new logic have a "multiple repeat" if I only specified one "at" symbol?
Kenneth Love
Treehouse Guest TeacherBecause you told it to? Code doesn't just suddenly decide to do whatever it wants :)
Your pattern, right now, says "find a word boundary, then 1 or more @
symbols, then...something. A count of 1? And then another word boundary".
That's not anything at all like an email address. We find email addresses before this point in the videos. Should probably go back and watch that part again.
michaelangelo owildeberry
18,173 Pointsfound the proper format in the sets video... I am always trying to make programming as easy, short and fast as possible, do you end up doing the same for your professional projects?
Kenneth Love
Treehouse Guest TeacherYou're learning. Don't worry about any of those three. Take as much time as needed to figure out a problem. Write as much code as you need to to make it work.
Mahdi Jafari
17,887 PointsKenneth Love
Hey all I got the answer and could pass the test thanks to you all but still I am confused about
[-\w\d+.]+@[-\w\d.]+
whats the meaning of the + in above code which is there after both of [] ?
Timothy Mattingly
15,931 PointsThe + is saying to find at least one or more of the characters from the set.