In the following code, I have run into a RecursionError: maximum recursion depth exceeded
.
def unpack(given):
for i in given:
if hasattr(i, '__iter__'):
yield from unpack(i)
else:
yield i
some_list = ['a', ['b', 'c'], 'd']
unpacked = list(unpack(some_list))
This works fine if I use some_list = [1, [2, [3]]]
, but not when I try it with strings.
I suspect my lack of knowledge in python. Any guidance appreciated.