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 trialMauro Y.
6,520 PointsBe sure you're lowercasing the string and splitting on all whitespace!
Don't understand this error. I lowercased and added the split in the white spaces. How this error came? Tested in my system and in the workspaces as well, in both I cannot see anything wrong.
# E.g. word_count("I do not like it Sam I Am") gets back a dictionary like:
# {'i': 2, 'do': 1, 'it': 1, 'sam': 1, 'like': 1, 'not': 1, 'am': 1}
# Lowercase the string to make it easier.
new_list = []
def word_count(words):
#lowercase the string and put in the list format
word_list = words.lower().split(' ')
#loop for count the words in the list
for word in word_list:
new_list.append(word)
new_list.append(word_list.count(word))
my_dict = {}
for index, item in enumerate(new_list):
if index % 2 == 0:
my_dict[item] = new_list[index+1]
return my_dict
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointstry no argument for the split method, so myString.split(). you are splitting on the space character only, not all whitespace, which includes characters like newlines, carriage returns and line feeds.
Mauro Y.
6,520 PointsFinally working. Thanks!