Skip to content Skip to sidebar Skip to footer

Control Recursion On Nested Lists / Strings

Assume I have the following input: items = [1, 2, [3, 4], (5, 6), 'ciao', range(3), (i for i in range(3, 6))] and I want to perform some recursive operation on items. For the sake

Solution 1:

Just add a length check next to the shallow check:

if isinstance(item, shallow) and len(item) == 1: 

Post a Comment for "Control Recursion On Nested Lists / Strings"