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 trial

Python Functional Python The Lambda Lambada Recursion

Andy Hughes
Andy Hughes
8,479 Points

Recursion challenge nightmare! I feel like a fraud!

I have to be honest. I didn’t even know where to start with this challenge and I’m sure there’s probably 4-5 different ways to get the output.

For anyone completing this, remember that TeamTreeHouse is looking for a specific set of criteria to pass the challenge. So you may come up with a perfectly acceptable way of getting the right output (via pycharm etc), that might not pass the challenge.

I myself started trying to go down the comprehension route. This to me seems logical as Kenneth keeps banging on about doing things in the simplest, most efficient way. But I couldn’t get it to work.

In the end, I cheated. I ended up searching other people’s answers and trying to understand the logic of what they did. Then I would try and complete the challenge working through the logic of what I was doing. But some parts still had me thinking “I don’t get why I’m writing this code, but everyone else seems to have done it.”

Doing that makes me feel like a fraud and that I’m not really learning, I’m just copying.

Not sure what the answer is, just wanted to share. This challenge feels like too much in just one task!

courses.py
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 x in data['prereqs']:
        pres.add(x['title'])
        prereqs(x, pres)
    return pres

2 Answers

Hey there Andy Hughes! I am sorry to hear that you are struggling. Sometimes it's necessary to see how other people worked out the solution in order to understand it. There are infinite ways of achieving a solution in programming, but you are right, the code challenges use regex in order to verify that the answer matches and unfortunately that can make it difficult to have the creative freedom to solve the problem in your own way. I definitely suggest using an IDE to test out various solutions in order to fully understand the concept. Hang in there!

jessicakincaid
jessicakincaid
21,833 Points

Don't feel like a fraud. We've all been there. Even if you didn't figure it out this time, trust me, you'll be working on a project later down the road and it will have sunk in. You'll say "Kenneth, I get it now!" Well, that happened for me, it takes a minute sometimes.