tree house challenge

IB Year 1 HL Computer Science
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
User avatar
minseok123
Helper!
Posts: 9
Joined: 17 Sep 2018, 10:14

tree house challenge

Post by minseok123 » 31 Oct 2018, 00:25

Hope you're enjoying your break :)
I'm not sure how to solve this challenge, link = https://teamtreehouse.com/library/pytho ... word-count

challenge task
Alright, this one might be a bit challenging but you've been doing great so far, so I'm sure you can manage it.

I need you to make a function named word_count. It should accept a single argument which will be a string. The function needs to return a dictionary. The keys in the dictionary will be each of the words in the string, lowercased. The values will be how many times that particular word appears in the string.

Check the comments below for an example.


my code

Code: Select all

# 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(words):
	words = words.lower().split()
    dictionary = {}
    for word in words:
        dictionary[word] = len(word)
    return dictionary
0 x

User avatar
Mr. MacKenty
Site Admin
Posts: 88
Joined: 28 Apr 2018, 17:06
Answers: 3

Re: tree house challenge

Post by Mr. MacKenty » 01 Nov 2018, 07:06

Hello Minseok123!! :-)

I am enjoying my break, thank you.

I would like you to please be MORE DESCRIPTIVE with your question. Specifically, I'd like to see:
  • Specifically what you tried to solve the problem
  • Specifically what made you think the program didn't work (it would helpful to include error messages here)
  • Specifically describe how your programs output is different than what you expected
  • Specifically state what hunches you have that might help you solve your problem
Once you reply to this message with the answer to those questions, I will do my best to help you.

Warmly,

Mr. MacKenty

minseok123 wrote:
31 Oct 2018, 00:25
Hope you're enjoying your break :)
I'm not sure how to solve this challenge, link = https://teamtreehouse.com/library/pytho ... word-count

challenge task
Alright, this one might be a bit challenging but you've been doing great so far, so I'm sure you can manage it.

I need you to make a function named word_count. It should accept a single argument which will be a string. The function needs to return a dictionary. The keys in the dictionary will be each of the words in the string, lowercased. The values will be how many times that particular word appears in the string.

Check the comments below for an example.


my code

Code: Select all

# 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(words):
	words = words.lower().split()
    dictionary = {}
    for word in words:
        dictionary[word] = len(word)
    return dictionary
0 x

Post Reply