Page 67 -
P. 67
meet python
Recursion to the rescue!
The use of a recursive function has allowed you to reduce 14 lines of messy,
hard-to-understand, brain-hurting code into a six-line function. Unlike the
earlier code that needs to be amended to support additional nested lists
(should the movie buff require them), the recursive function does not need to
change to process any depth of nested lists properly.
Python 3 defaults its recursion limit to 1,000, which is a lot of lists of lists of lists
of lists…and this limit can be changed should you ever need even more depth
than that.
Ah, yes, that’s terrific! I can now
relax, knowing that your code can
process my movie data. I really
should’ve done this years ago...
What a great start!
By taking advantage of functions and recursion, you’ve solved the code
complexity problems that had crept into your earlier list-processing code.
By creating print_lol(), you’ve produced a reusable chunk of code that
can be put to use in many places in your (and others) programs.
You’re well on your way to putting Python to work!
you are here 4 31