I am beginner in python and I'm wondering which approach is better assuming I have the following code and which one should be used in production.
d = {}
d['a'] = set([0,1,2,0])
d['b'] = set([1,2,1,2])
Approach 1:
try:
print(d['c'])
except:
print(set())
Approach 2:
try:
ans = d['c']
except:
ans = set()
print(ans)
Approach 3:
if 'c' in d.keys():
print(d['c'])
else:
print(set())
Approach 4:
if 'a' in d.keys():
ans = d['c']
else:
ans = set()
print(ans)