If you want to flatten arbitrarily nested iterables, you could try this function:
def flatten(x):
try:
it = iter(x)
except TypeError:
yield x
else:
for i in it:
for j in flatten(i):
yield j
Example:
a = [2, 9, [1, 13], 8, 6]
list(flatten(a))
# [2, 9, 1, 13, 8, 6]
Note that the function would also flatten out strings to single characters.