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

Sandra Gury
Sandra Gury
6,911 Points

Set Math challenge task 1 of 2

My code returns me this: treehouse:~/workspace$ python test.py
['P', 'y', 't', 'h', 'o', 'n', ' ', 'B', 'a', 's', 'i', 'c', 's'] I don't get why... Can anybody help me with that?

    "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 (topic):
    list_of_courses =[]

    for key in COURSES:
        if topic & COURSES[key]:

1 Answer

You need to use append() instead of extend(). extend() is adding each item (ie, character) from the course name to list_of_courses. Take a look here: https://stackoverflow.com/questions/252703/difference-between-append-vs-extend-list-methods-in-python

Also, there is no need for else: continue. The loop will not do anything to the item if it doesn't fit the condition.