Python Python Collections (2016, retired 2019) Dictionaries Word Count

word_count I have checked my code in the workspaces and i got the expected output But cannot check it

I still got Unexpected Output when i check it in the units: https://teamtreehouse.com/library/python-collections-2/dictionaries/word-count

wordcount.py
# 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.
def word_count(item):
    word_list=item.split(" ")

    low_word_list=[]
    for word in word_list:
        low_word=word.lower()
        low_word_list.append(low_word)

    i=0
    word_dict={}
    while i<len(low_word_list):
        j=1
        if low_word_list[i] not in word_dict.keys():
            word_dict.update({low_word_list[i]:j})
            i+=1
        else:
            m=word_dict[low_word_list[i]]+1
            word_dict.update({low_word_list[i]:m})
            i+=1

    return word_dict

1 Answer

Steven Parker
Steven Parker
171,345 Points

You're really close, and the "Bummer" message gave you a hint: "Be sure you're lowercasing the string and splitting on all whitespace!".

To split on "all whitespace" the argument to "split" should be left empty or set to None.

OH! I got it! Thank you!!!

Steven Parker
Steven Parker
171,345 Points

chunjie liu — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!