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 trialHussein Amr
2,461 PointsI don't get the question
any ideas
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(topics):
inters = []
for k,v in COURSES:
if k & v:
inters.append(k)
return inters
1 Answer
Ismail KOÇ
1,748 Pointsif k & v:
this statement intersection compares keys and values, this challenge wants intersection your argument (topics) and values of COURSES for write course name (COURSES[key]) and return intersection.
if input_arg & COURSES[key]:
check this and write what do you need.
Michael Hulet
47,913 PointsHi Ismail! For future reference, it's frowned upon around here to write a copy/paste answer with no explanation at all. If you'd like, feel free to re-post your code, but be sure to thoroughly explain why it's correct. Also, in Python, the &
does a bitwise AND
operation, not a logical and
, which is probably what you want. A logical and
in Python is just the word and
. Happy coding, and thanks for helping out around the Community!
Ismail KOÇ
1,748 Pointsi will pay attention this for next time
Hussein Amr
2,461 PointsIsmail KOÇ did that but didn't work
def covers(topics):
for v in COURSES:
if topics & (COURSES[v]):
return topics.intersection(COURSES[v])
Ismail KOÇ
1,748 Pointsdef covers(topics): # ------> No space for v in COURSES: # ------> 4 spaces if topics & (COURSES[v]): # ------> 8 spaces return topics.intersection(COURSES[v]) # ------> 12 spacespython has space sensitive for ex:
for i in range(1,5) # loop 1 -----> No space for j in [6,7,8] # loop 2 -----> 4 space for k in (9,0) # loop 3 -----> 8 space
in this program :
- loop 3 in loop 2
- loop 2 in loop 1
look your code again:
def covers(topics): # ------> No space
for v in COURSES: # ------> 4 spaces
if topics & (COURSES[v]): # ------> 8 spaces
return topics.intersection(COURSES[v]) # ------> 12 spaces
- for loop in (covers) function
- if condution in for loop
- return in if condution
- so you need to move return 8 space backward (delete 8 spaces) because return needs to independent of for loop.
Hussein Amr
2,461 PointsHussein Amr
2,461 PointsVictor Santiago it didn't work bruh