id_dict = {1 : 'cat', 2 : 'dog', 3 : 'fish', 4 : 'cow' }
feature_list = ['cat','cat', 'dog', 'dog','fish', 'calf']
id_list = ['nan','nan','nan','nan','nan', 'nan']
for key, value in id_dict.items():
for item in feature_list:
if item == value:
id_list[feature_list.index(value)] = key
How can I make sure that the id_list is updated with [1,1,2,2,3] when the values match and pass over when a value is not in there ? Currently, only the first value is being updated. Current Output: [1, 'nan', 2, 'nan', 3]