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 trialVashisth Bhatt
Python Web Development Techdegree Student 6,786 Pointswhy 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?
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
Treehouse Moderator 68,457 PointsThere 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 usetemp = list(word)
- You are modifying the
for
loop iterable. This is not good and will return erroneous results. Best to use a copy such asfor letter in temp.copy()
orfor letter in temp[:]
. The latter is slice notation that you'll learn more about later. This way, as you modifytemp
, 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!!
Vashisth Bhatt
Python Web Development Techdegree Student 6,786 Pointsthanks for the help.but now i am getting error of "can't delete function call".What thing i am doing wrong?
Chris Freeman
Treehouse Moderator 68,457 PointsI've updated my answer above.