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 trialfahad lashari
7,693 PointsReally stuck on this problem. Can someone help out or provide a hint?
Just a newbie here. I am able to get the values of the courses where the supplied set and the values from the COURSES dictionary overlap. However I am struggling to get the key of the courses. I have managed to get the actual courses doing the following:
COURSES = {
"Python Basics": {"Python", "functions", "variables",
"booleans", "integers", "floats",
"arrays", "strings", "exceptions",
"conditions", "input", "loops"},
"Java Basics": {"Java", "strings", "variables",
"input", "exceptions", "integers",
"booleans", "loops"},
"PHP Basics": {"PHP", "variables", "conditions",
"integers", "floats", "strings",
"booleans", "HTML"},
"Ruby Basics": {"Ruby", "strings", "floats",
"integers", "conditions",
"functions", "input"}
}
def covers(set):
list = []
for value in COURSES.values():
if set.intersection(value):
list.append(value)
return list
And I tried to solve this using dictionary unpacking however I couldn't achieve the desired result:
def covers(set):
list = []
for key, value in COURSES.items():
if set.intersection(value):
list.append(key)
return list
Any help would be greatly appreciated.
Kind regards,
Fahad
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi fahad,
You're on the right track with your second attempt but you have your return statement indented 1 level too far. Should be lined up with the for
Also, I would recommend that you don't use set
and list
for variable names since these are built in types.