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 trialAlberto Tonegari
Full Stack JavaScript Techdegree Student 6,074 PointsPython Collections: sets
I can't figure it out, what am i doing wrong in the "covers_all" function? This are the steps: First i declared an empty list, then i loop through all the values and keys of the dictionary, i compare if val is in the dictionary values using issuperset(), after that i put the corresponding key in my list. But it does not work, i think i have a 'bug' in my logic. Can you help, please?
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(val):
list_of_courses = []
for word in val:
for basic in COURSES:
if word in COURSES[basic]:
list_of_courses.append(basic)
return list_of_courses
def covers_all(val):
new_list = []
for keys, values in COURSES.items():
if val.issuperset(values):
new_list.append(keys)
return new_list
1 Answer
Salam El Bsat
2,005 Pointsval.issuperset should be val.issubset, since .issuperset and .issubset follows the natural flow where you are checking if the set where the method is being applied is a sub/super set of the argument passed to the method.
In this exercise, val, being the argument passed to cover_all method should be a subset of any of the values to append its key to the list and not the opposite.
Hope this helps, Salam :)
Alberto Tonegari
Full Stack JavaScript Techdegree Student 6,074 PointsAlberto Tonegari
Full Stack JavaScript Techdegree Student 6,074 PointsHello,
Thank you for your response, it was very helpful.
Good day, Alberto