Chapter 5 Exercise Set 4: Recursion Exercises

Counting the length of sequences by traversal revisited

In Counting the length of sequences by traversal you were asked to traverse a sequence and print out the length of each element. In this exercise you will improve on that solution by:

  1. Handle cases where the element is an int or float and print None for length.

  2. Recursively print out the length of all elements which are nested sequences.

['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]