Having this dictionary and list:
input_list = {"This_is_House1_Test1": "one", "Also_House2_Mother": "two", "Fefe_House3_Father": "three"}
house_list = [1, 2]
For the example above, I have house_list
with 1
and 2
, so I just want to maintain on the dictionary the keys containing House1
or House2
, and remove the rest of them.
My desired output for the simplified input above is:
{"This_is_House1_Test1": "one", "Also_House2_Mother": "two"}
This is my try with no luck:
for key in list(input_list.keys()):
for house_id in house_list:
if "House" + str(house_id) not in key:
input_list.pop(key)
Thanks in advance!