inputList = [['a', ['b', 'c', 'd'], [['e']], 'f'], ['g']]
flattenedList = magic(inputList)
flatResults = calculations(flattenedList)
resultify(inputList, flatResults)

def resultify(inputList, flatResults, answer=None):
    if answer is None:
        answer = []
if not inputList:
    return answer
for elem in inputList:
    if not isinstance(elem, list):
        answer.append(flatResults.pop(0))
else:
    answer.append(resultify(elem, flatResults, []))
return answer
Каков наилучший способ разделить один список на несколько списков на основе шаблона в Python?