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 trialAndy McDonald
Python Development Techdegree Graduate 13,801 PointsCalling the function within the function
This part is really hard for me to conceptualize, to run the function again an return new values. I figure I have to call it based upon the values I got on the first time around but I'm not sure how to turn the function on those items within the items in the dict. I just really don't know the syntax for doing that.
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 set()
for pre in data['prereqs']:
pres.add(pre['title'])
for i in pres:
prereqs(data['title'=i])
return pres
Chris Freeman
Treehouse Moderator 68,457 PointsAndy McDonald do you need any additional help on this?
1 Answer
Andy McDonald
Python Development Techdegree Graduate 13,801 PointsHi self, look at this answer that Chris gave a while ago: https://teamtreehouse.com/community/another-recursion-in-python-functional-python-question
Chris Freeman
Treehouse Moderator 68,457 PointsGood job Self! 🤣🤣🤣
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsCheck out a previous answer I gave on thinking through the recursion. Let me know if you need further help. Gook luck!!