Sunday, February 16, 2014

Week #6

This week I finally grasped the full extent of how useful TreeLists can be. I was reading over treelist.py which was posted last week. I knew it might be on the midterm during the week and so I read over it, and fell against an old enemy of mine: recursion:

def inorder(tl: 'TreeList') -> list:
    """
    Return a list of values of tl inorder

    >>> inorder([5, [4, None, None], [3, [2, None, None], [1, None, None]]])
    [4, 5, 2, 3, 1]
    """

    return ((inorder(tl[1]) if tl[1] else []) +
            [tl[0]] +
            (inorder(tl[2]) if tl[2] else []))

The return statement basically parses a recursive statement for elements prior and another recursive statement added to end. It took me a long time to understand it as for me I understood the base of inorder going over the method for each element but was very confused as to why exactly this happened. Wrote it down as a question to hopefully ask Danny during office hours or a TA or a classmate.

I learned something new in the form of TreeList, I knew what they were and would be able to visualize it, however writing them down as code was a different challenge. Using posted codes and resources (such as Coding like a Pythonista) I was able to get a full grasp. Also have a bunch of Youtube videos just waiting to be watched that explain in different ways. I get the general aspects of it, I struggle however with its implementation with recursion.

Recursion keeps on challenging me and frustrate me. I feel like I am a very logical person, I love understandings the crooks and hidden aspects of things, however, the logic of doing a 'leap of faith' has me all mixed up. Hoping to get it soon, won't give up on it.

Interesting SLOG of the week:

http://lavendercsc148.blogspot.ca/


For Week #6 Lavender broke down the Assignment 2 which was due the previous week, with this blog entry being the first part (part 2 also discussed in my Week 7 SLOG). While part 2 focuses on the regex_match code, this week is all about the __init__ required for the Assignment. She talked about where she had difficulties which coincided with mine, however she found a better solution (lucky me!!! (<- really hard to convey sarcasm over the internet)) and used a helper function which I should have done...

No comments:

Post a Comment