How to match two lists and insert into specific value?

I have two lists

a = ['b','c','a','d','v']
g = [{'c':'1'},{'c':'2'},{'c':'3'},{'d':'1'},{'d':'2'}]

I want to match the key in the dictionary in the list g to the elements in list a, if they are matched, the elements in list g will be inserted into list a.

The desired outcome is:

['b','c',{'c':'1'},{'c':'2'},{'c':'3'},'a','d',{'d':'1'},{'d':'2'},'v']


Read more here: https://stackoverflow.com/questions/68465066/how-to-match-two-lists-and-insert-into-specific-value

Content Attribution

This content was originally published by Nok at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: