def all_paths(l):
    if 1 == len(l):
        return [l]
down = all_paths(l[1:])
if type(l[0]) in [list]:
    return [([ll] + k) for k in down for ll in l[0]]
return [([l[0]] + k) for k in down]
l = [['a', 'b'], 'c', ['d', 'e'], ['f', 'g'], 'h']
for i in all_paths(l):
    pass
Recursive "all paths" through a list of lists - Python