Friday, January 30, 2015

WEEK 4 SLOG

   In this week, I learn the concepts about recursion on nested lists, recursion with turtles.

   We start to use recursion to write functions like sum_list and depth. These functions are required to implement actions to add or calculate depth of list in nested lists. Usually we build the function using list comprehensions. It is not a difficult concept to understand and I really enjoy to learn and use when writing code. However, one thing frustrates me is that some function call itself in list recursion. I put the example function code below. The problem is that I cannot understand if L = [1, [2, 3], 4] ) , when it enters the if statement and return 1 + max([depth(x) for x in L]). During the loop (list comprehension) , when x is any number or list in L, it will call depth(x). When x = 1, it enters else statement and return 0. This is the big problem that I catch with. In my view,  the function will return 0. But the truth is that after recording depth(0) = 0, the function will continue to implement list comprehension. In order to figure out my puzzle, l ask my classmate and then understand . Since calling depth(1) is in the process, it will not return and exit. I think it is so helpful  and fast for me to ask classmates relating to problems of learning. They can give you detailed answers.

   Furthermore, I think l am not confident  about the material that l learn in this week, because l did take more practice(using them to write some functions). In the weekend, l plan to do some by writing the past midterm paper.

def depth(L):
    ''' (list or non-list) -> int

    Return 0 if L is a non-list, or 1 + maximum
    depth of elements of L, a possibly nested
    list of objects

    >>> depth(3)
    0
    >>> depth([])
    1
    >>> depth([1, 2, 3])
    1
    >>> depth([1, [2, 3], 4])
    2
    '''
    # find the bug!
    if isinstance(L, list):
        return 1 + max([depth(x) for x in L])
    else: # L is not a list

        return 0

Wednesday, January 21, 2015

Why geeks should write


The word geek usually describes a person who has excessive enthusiasm for and some expertise about computer science and internet technology(technologically oriented geeks). Such group of people invest unlimited time in writing code and designing softwares. Geeks tend to operate in research departments, laboratories and support functions. They master the latest and most cutting-edge internet technology, so they can easily solve a complicated problem related to computer simply by a piece of code, or a program. It is very normal for geeks to use computer to write code using different programming languages, like python. If they do not write, obviously they won’t be a geek. Since geeks often indulge in developing software or learning new computer technology, they would rather sacrifice their own social time to do this. Not only do geeks write code, but they intend to share their technology and thought. If they don't communicate with others, they will not share their achievements to others,the techniques they created will not be spread. Now, geeks play important roles in developing global economy and society, they increasingly occupy senior corporate positions, and wield considerable commercial and political influence. The most famous geek is Bill Gates, the CEO of the world’s largest technology firms, all most every family in the world use Microsoft. Thus, such kind of geeks need to communicate to their colleagues or subordinates in order to designing fabulous softwares or internet products. I want to show another example Facebook, it is so hard for only one person creating such an amazing website. Geeks should write not only because writing codes, but communicating with others for promoting the development of the computer technology.