word count

Run Settings
LanguagePython
Language Version
Run Command
""" Write a Python function that takes a string as input and returns the count of each word in the string. """ def word_count(x): words = x.split() # copy string to list "words" # print(type(words)) # add words into list # print(words) # show word list word_count_dict = {} # create dictionary # print("word_count_dict : ", type(word_count_dict), "\n") for word in words: # print("current word is ", word) if word in word_count_dict: word_count_dict[word] += 1 else: word_count_dict[word] = 1 # print(word_count_dict) # check point return word_count_dict result = word_count("the quick brown fox jumps over the lazy dog") print(result)
Editor Settings
Theme
Key bindings
Full width
Lines