Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python The Lambda Lambada Recursion

Andy Hughes
Andy Hughes
8,114 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

1 Answer

Mel Rumsey
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

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!