These are my inputs, pretty-printed for better readability
input1 = [{
"ID": "1",
"SequenceNum": 1
},
{
"ID": "2",
"SequenceNum": 2
},
{
"ID": "3",
"SequenceNum": 3
},
{
"ID": "4",
"SequenceNum": 4
}]
input2 = ['4', '1']
The values contained in input2 are basically the values of the 'ID' key seen in input1
The output will be a list of dictionaries where input1[index]['ID'] == input2[index_element].
Expected output -> [{"ID": "4","SequenceNum": 4},{"ID": "1","SequenceNum": 1}]
I have solved this using the following lines of code:
match_list = []
for idx,val in enumerate(input1):
match_list.append(val['ID'])
return_list = []
for idx,val in enumerate(input2):
if val in match_list:
get_idx = match_list.index(val)
return_list.append(input1[get_idx])
While it works it doesn't feel like the most optimal nor the cleanest way to write code. I apologize for the basic question, I am not a very experienced programmer.