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 trialSandra Gury
6,911 PointsSet 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?
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 (topic):
list_of_courses =[]
for key in COURSES:
if topic & COURSES[key]:
list_of_courses.extend(key)
else:
continue
return(list_of_courses)
1 Answer
ursaminor
11,271 PointsYou 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.