I want to get the key that has the minimum value in a given dictionary, but with the condition that this key is in a given list
for example this would be the dictionary.
dict = {
's': 0,
'y': 5,
't': 8,
'z': 7,
'x': 9
}
and this is the list with the keys to be checked
list = ['y', 'z', 't', 'x']
I made this implementation, but I think it could be optimized or made in a more pythonic way.
a = float("inf")
for key in dict:
if key in list:
temp=a
a = min(a,dict[key])
if a < temp:
minimum = key