I have a set and dictionary and a value = 5
v = s = {\'a\', \'b\', \'c\'}
d = {\'b\':5 //<--new value}
If the key \'b\' in dictionary d
The expanded form of what you're trying to achieve is
a = {}
for k in v:
a[k] = d[k] if k in d else 0
where d[k] if k in d else 0
is the Python's version of ternary operator. See? You need to drop k:
from the right part of the expression:
{k: d[k] if k in d else 0 for k in v} # ≡ {k: (d[k] if k in d else 0) for k in v}
You can write it concisely like
a = {k: d.get(k, 0) for k in d}