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 Python Collections (2016, retired 2019) Lists Disemvowel

Vashisth Bhatt
seal-mask
.a{fill-rule:evenodd;}techdegree
Vashisth Bhatt
Python Web Development Techdegree Student 6,786 Points

why is this indentation error is coming in my code.what actaally happens when this error arises?

inconsistent uses of tabs and workspace error is popppping up.can anybody give their opinion and help?

disemvowel.py
def disemvowel(word):
    temp=[]
    temp.extend("word")
    i=0
    for letter in temp:
        if(letter.upper()=='A' or letter.upper()=='E' or letter.upper()=='I' or letter.upper()=='O' or letter.upper()=='U'):
            del temp(i)
            i++
    word=temp
    return word

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

There is a tab in your code before the "i++". That should be replaced with spaces. When there is a mixed use of Tabs and Spaces, Python can not be sure of the intended indentation, so it raises an error that stops the execution.

Also, "i++" is not valid Python. The pythonic way is to use i += 1

Edit: I hadn't looked beyond the indentation error, here are more suggestions:

  • While temp.extend("word") works, a more readable way is to use temp = list(word)
  • You are modifying the for loop iterable. This is not good and will return erroneous results. Best to use a copy such as for letter in temp.copy() or for letter in temp[:]. The latter is slice notation that you'll learn more about later. This way, as you modify temp, the loop can continue to operate on the copy.
  • Using the i to count the loop is OK for now. Later on you'll learn about the enumerate() function.
  • To join the letters left in the list to return use "".join(temp). This can be returned directly and does not need to be assigned to a variable

Post back if you need more help. Good luck!!