Let's say that I have a list l=[1, 2, 3, 4] and a dictionary d={2:a, 4:b}. I'd like to extract the values of d only in the key is also in my list and put the result in a new list. This is what I've tried so far:
new_l=[]
for i in l:
for key in d.keys():
if key in l:
new_l.append(d[key])
print (new_l)
Thank you in advance for your help.