Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,328 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.