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

wordcount ahoy

So, how come this doesnt work? For funzies I added in the section of code i was using to test so you could see that it does indeed work in workspace or wherever.

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.
from collections import Counter
def word_count(argumentative_waffle):
    angry_badger = argumentative_waffle.lower().split(" ")   
    return(dict(Counter(angry_badger)))


from collections import Counter
def word_count(argumentative_waffle):
    angry_badger = argumentative_waffle.lower().split(" ")   
    print(dict(Counter(angry_badger)))

word_count('Oh my God Becky look at her butt It is so big she looks like One of those rap guys girlfriends'
            'But ya know who understands those rap guys They only talk to her because She looks like a total prostitute kay' 
            'I mean her butt is just so big I cant believe its just so round its like out thereI mean gross look'
            'Shes just so blah I like big butts and I can not lie You other brothers cant deny That when a girl walks in with an itty bitty waist'
            'And a round thing in your face You get sprung want to pull up tough Cause you notice that butt was stuffed Deep in the jeans shes wearing'
            'Im hooked and I cant stop staring Oh baby I want to get witcha And take your picture')

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Change the argument to .split() to the default to split on Whitespace instead of a literal Space .split(" ") and it will pass!

Aha, my savior has arrived! I wonder why it doesn't like spaces..

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Using a Space is insufficient because the words may be separated by multiple spaces or a Tab.

Michael Hulet
Michael Hulet
47,913 Points

This is a clever solution, and I like it a lot (tbh I didn't know collections.Counter existed), but I don't think you're allowed to import any modules for this challenge. I'm afraid you'll have to write the logic yourself

So any idea whats wrong with this one then?

def word_count(argumentative_waffle):

    angry_badger = argumentative_waffle.lower().split(" ")

    some_other_name = []

    candy_coated_armadillo = []

    for word in angry_badger:

        if word not in some_other_name:

            some_other_name.append(word)

    for word in some_other_name:

        candy_coated_armadillo.append(angry_badger.count(word))

    print(dict(zip(some_other_name,candy_coated_armadillo)))

(changed it to return for the challenge)

Michael Hulet
Michael Hulet
47,913 Points

To test, I just pasted in an answer that I know to be correct and has worked for me before, and it didn't work here. I just reported it. Hopefully somebody will see my message in the morning