[Solved] evaluate a python string expression using dictionary values


At the end I found a solution to my problem:

text = "'my_home1' in houses.split(',') and '2018' in iphone.split(',') and 14 < mask"
dict = {'house' : 'my_home1,my_home2', 'iphone' : '2015,2018', 'mask' : '15' }

expression = 'false'

for key in dict.keys():
    if isinstance(dict.get(key), str):
        text = re.sub(key, '\'{}\''.format(dict.get(key)), text)
    else:
        text = re.sub(key, dict.get(key), text)

eval(text)

solved evaluate a python string expression using dictionary values