# credit to Stack Overflow user in the source link # d is your dictionary if key not in d: d[key] = value
if key not in d: d[key] = value