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 trial

Python Regular Expressions in Python Introduction to Regular Expressions Email

igor corrales
igor corrales
2,474 Points

Iḿ stuck with this problem

When I check this in my console is working out !! so I don't understand the error that I get.

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(basura):
        a = re.findall(r'[-\w\d.]+@[-\w\d.]+', basura)
        return a

4 Answers

hi igor,

You get that error because if you look at the emails provided in this example, you will find there is a "+" character in the last email (test+case@example.co.uk) that we need to include in the first set before "@" symbol .. so we can capture that email too with our regular expression..

So you could modify your re to look like this and this will work for the current challenge..

def find_emails(basura):
    a = re.findall(r'[-+\w\d.]+@[-\w\d.]+', basura)
    return a
igor corrales
igor corrales
2,474 Points

Thanks a lot Karim !!! but I'm still with the same error .......I don't understand why ??

you are welcome, igor..

Please, could you tell me the error message that appears to you?

I tested the code and it's working fine, I get a list of 3 emails:

['kenneth.love@teamtreehouse.com', 'ryan@teamtreehouse.com', 'test+case@example.co.uk']

igor corrales
igor corrales
2,474 Points

Hi Karim!!

The error is not very helpful :

Bummer: TabError: return a

Hi igor,

may be it's indentation problem.. Please refer to this solution: Bummer: TabError :inconsistent use of tabs and spaces

Answer by Steven Parker:

Python allows you to indent using spaces or tabs, but you must pick one or the other and use it consistently.

Please, try to rewrite your code using only tabs or spaces for indentation and see if it works..

igor corrales
igor corrales
2,474 Points

It was a ..... i don't know what but I did exactly the same and it's works out !!! Ths system is very frustranting !!!!

Thanks a lot

You are welcome, igor :)

Python rely on indentation for code blocks. Sometimes this could get out of hands if not doing it correctly.

So, most Python programmers follow Style Guide for Python Code -also known as "PEP 8"-. Its goal is to promote readability and consistency in Python code bases.

Also there is a course here at "TreeHouse" explaining this, you can find it here: Write Better Python

In the end, I'm glad that you were able to solve it :)