The nested structure here is good for being traversed by a recursive algorithm:
x = ['a', '1', ['c', 'd', ['e', ['f', '123']]]]
def recurse(y):
left,right = [],None
# Here we loop over the elements and whenever we encounter
# another list, we recurse.
for elem in y:
if isinstance(elem,list):
right = recurse(elem)
else:
left.append(elem)
# If there is no further nested list, return only the
# concatenated values, else return the concatenated values
# and the next list in the nest.
if right is None:
return ["".join(left)]
else:
return ["".join(left),right]
print recurse(x)
The output from this is:
['a1', ['cd', ['e', ['f123']]]]