You can use a dictionary view with set operations to select only keys from your input sequence:
min(f.viewkeys() & o, key=f.get)
In Python 3, all you need to use is:
min(f.keys() & o, key=f.get)
as the dict.keys()
method now returns dictionary views.
Alternatively, you could use a key function that excludes keys you don't want to include:
set_o = set(o)
min(f, key=lambda k: f[k] if k in set_o else float('inf'))
I'm using a set here to make membership tests efficient. float('inf')
(positive infinity) is guaranteed to always test larger than any other value.
Demo:
>>> o = [1, 2, 4, 6]
>>> f = {1: 10, 2: 5, 3: 1, 4: 3, 5: 7, 6: 9}
>>> min(f.viewkeys() & o, key=f.get)
4
>>> set_o = set(o)
>>> min(f, key=lambda k: f[k] if k in set_o else float('inf'))
4