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

I am getting the correct answer in my IDE but the Check Work in the challenge question returning (didn't get the right..

I wish there is a way to see what is the output of my function when it is run by the auto-check. The following is my function, which is returning the correct result according to the requirement: def covers(set1): list_cor = list() list_courses = list() for value in COURSES.values(): list_courses.append(set1.intersection(value)) for i in list_courses: for x in i: list_cor.append(str(x) + " Basics" )

return (json.dumps(list_cor))
sets.py
import json
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(set1):
    list_cor = list()
    list_courses = list()
    for value in COURSES.values():
        list_courses.append(set1.intersection(value))
    for i in list_courses:
        for x in i:
            list_cor.append(str(x) + " Basics" )

    return (json.dumps(list_cor))

3 Answers

I am not sure if the question is only asking to return the the common courses names plus the Basics postfix string or return the common course names with every string from the value of the field of the dictionary for that common course. for example: Is it asking for ["Python Basics "] if only Python is common or Is it asking to return ['Python Basics', 'Python strings', 'Python variables' .......] if only Python is common

Seth Kroger
Seth Kroger
56,413 Points

Whenever this situation crops up, when a solution written in Workspaces or an IDE looks like it works but the challenge doesn't accept it, it's almost always because the challenge is looking for a specific format. From the challenge question it's looking for a regular Python list, not a JSON string or list.

Thank you so much Seth for you quick respond on Saturday! I have tried returning the list in a regular Python list format but I still got the same message. I only used the JSON library because the example of the returned list in the question is shown with Double quotes rather than single quotes.