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) Sets Set Math

Jaleel Rivera
Jaleel Rivera
1,338 Points

How could i make this code better

I answered the question but I wanted to know how could I solve this problem more efficiently

my code

def covers_all(topics): topics_covered = [] counter = 0 for x in COURSES: counter = 0 for y in topics: if y in COURSES[x] counter += 1 if counter == len(topics): topics_covered.append(x) return topics_covered

1 Answer

Steven Parker
Steven Parker
229,644 Points

While counting in nested loops does produce the same results, I think the point of the exercise was to practice using sets and set math operations. The previous video had examples that could be applied here.