Skip to content

Instantly share code, notes, and snippets.

@airekans
Created January 31, 2018 22:48
Show Gist options
  • Save airekans/7427b159f71e8c87f3a1754c9da3cca6 to your computer and use it in GitHub Desktop.
Save airekans/7427b159f71e8c87f3a1754c9da3cca6 to your computer and use it in GitHub Desktop.
A = [1, [2, 3], [4, 5, 6], 7] B = [2, 3, 4, 5, 6, 7, 8] How to transform B into the same structure as A? E.g. B' = [2, [3, 4], [5, 6, 7], 8]
def func(l1, l2):
def traverse(l1, l2, i):
res = []
for e in l1:
if isinstance(e, list):
res.append(traverse(e, l2, i))
else:
res.append(l2[i[0]])
i[0] += 1
return res
return traverse(l1, l2, [0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment