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) Dictionaries Word Count

This answer works perfectly on pycharm... what gives?

What gives? this code words perfectly on pycharm.

wordcount.py
def word_count(x):
    dic = {}
    words = x.lower().split()
    for word in words:
        dic.update({word: words.count(word)})
    return dic

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have a mix of spaces and tabs in your code indentation. The code challenges flag that as an error. I suggest only using spaces.

Thanks Chris, but how did you know that just by looking at the code?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I can’t necessarily β€œsee it”. If i run your code as posted and it passes then it must be a hidden syntax issue. I then grab your code and run it in my local REPL. The inconsistent use error then pops up.

Some editors automatically correct indentation errors on a cut and paste.

Oh ok that makes more sense. Just to reiterate, instead of using tab, I should use 4 spaces every time I want to indent a line of code?