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
Elizabeth McInerney
3,175 PointsPython Collections/Dictionaries/Word Count
The following code works in Workstation but gives me the following error in the course "Bummer! isinstance()arg2 must be a type or a tuple of types."
string = "I am that I am"
dict = {}
def word_count(string):
string2 = string.lower()
list = string2.split()
for word in list:
dict[word]=0
for word in list:
if word in dict:
dict[word] += 1
word_count(string)
1 Answer
Brian Fuller
6,699 PointsYou should avoid using variable names that are keywords in Python. This will often trip up the Python interpreter. You did this twice, with the variable names dict and list, which are the names of Python types. Use names like my_dict or m_dict and my_list or m_list instead, and the interpreter should like your code.
Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsThanks so much. That did the trick. I keep forgetting to return the thing my function created, but once I also added a return statement, along with your suggestions, it worked!