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:
Handle cases where the element is an
int
orfloat
and printNone
for length.Recursively print out the length of all elements which are nested sequences.
['spam!', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]]