Friday, February 28, 2014

    From week 4 till now, the class have been focused on recursion a lot. Most of the time we have been trying to understand and be able to use recursion.
    So, what is recursion?
    I'll provide a example:
    def re(s:lst):
        for i in s
            if i == []:
                return True
            elif i.isinstance(i,list):
                re(i)
            else:
                pass
        return False


this is a simple example of recursion. it checks if there is a empty list in the big list, and will return True if there is. if there is a list in the big list, it will rerun the function re again.

    Basically recursion is calling the function inside the function.

No comments:

Post a Comment