I am trying to append elements from a multi-dimensional list into a 2nd multi-dimensional list. Here is the code I wrote -
my_list = [[['b', ['a'], 'c'], ['d', ['a', 'b'], 'e']],
[['j', ['a', 'f']], ['q', 't']]]
ref_list = [[['q', 'w', 't'], ['y', 'u']],
[['s', 'o'], ['p', 'k', 'l']]]
newlist = []
for num, i in enumerate(my_list):
small_list = []
for num_1, j in enumerate(i):
semilist = []
for k in j:
if isinstance(k, list):
onelist = []
for a in k:
for ii in ref_list[num][num_1]:
onelist.append(ii)
semilist.append(onelist)
else:
semilist.append(k)
small_list.append(semilist)
newlist.append(small_list)
print(newlist)
The output I am getting is -
[[['b', ['q', 'w', 't'], 'c'], ['d', ['y', 'u', 'y', 'u'], 'e']], [['j', ['s', 'o', 's', 'o']], ['q', 't']]]
The output I am looking for is of sort -
[[['b', ['q', 'w', 't'], 'c'], ['d', ['y', 'u'], 'e']], [['j', ['s', 'o']], ['p', 'k', 'l']]]
I want to replace elements of innermost list of "my_list" with the elements of the "ref_list".