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 trialTim Oltman
7,730 PointsThis question is extremely difficult or I'm just missing something here. Does it involve set unions?
This exercise is extremely difficult or I'm missing something very simple. It seems that set.add() only works for adding a single element to a set. Do we need to work with set unions for this question?
I'm very frustrated because usually these types of exercises only take a few minutes at the most if you have watched the videos and follow the instructions closely. I'm been at this for several hours at least over a couple of days.
courses = {'count': 2,
'title': 'Django Basics',
'prereqs': [{'count': 3,
'title': 'Object-Oriented Python',
'prereqs': [{'count': 1,
'title': 'Python Collections',
'prereqs': [{'count':0,
'title': 'Python Basics',
'prereqs': []}]},
{'count': 0,
'title': 'Python Basics',
'prereqs': []},
{'count': 0,
'title': 'Setting Up a Local Python Environment',
'prereqs': []}]},
{'count': 0,
'title': 'Flask Basics',
'prereqs': []}]}
def prereqs(data, pres=None):
pres = pres or prereqs(data['prereqs']).add(data['title'])
for course in data['prereqs']:
prereqs(data['prereqs'])
2 Answers
Steven Parker
231,268 PointsYou're close, but:
- the original line that initializes "pres" should be left as-is
- the loop should add the current item's title to "pres" before the recursive call
- after the loop finishes, return "pres"
Tim Oltman
7,730 PointsThanks, I finally got it.