Created
January 31, 2018 22:48
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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