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

For fun, I did a list version of this challenge, appending a tuple for the word value pair

It wouldn't pass the challenge...but it wasn't intended to. I just wanted to try it with a list instead if a dictionary.

word_list = ["my", "fine", "fine", "pony", "pony", "pony"]
count_list = []

for word in word_list:
    count = word_list.count(word)
    count_list.append((word, count))
print(set(count_list))

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Well it wont pass the challenge because the challenge is looking for different requirements, but it definitely is an alternative way of grouping the keywords and counts together using sets/tuples.

My output from your code.

>>> {('fine', 2), ('pony', 3), ('my', 1)}

Now all you need is to wrap it up in a nice function so you can call that function and pass it any list of strings to count and print out. :)