From here, it seems like I am wrong, to be updated asap.
Is this as simple as it can be ? Not quite ? The check for d.get(my_key)
is actually to distinguish "test3" from the other values. It could be easier to just do the sameobvious thing for all values and then overrideinstead of trying to retrieve stuff from the "test3" value.dict :
def my_function(my_string, my_key):
d = {'test' + str(i): {} for i in range(3)}
if my_string:
d[my_key]d['test3'] = {my_string'a_key': None'a_value'}
elseif my_string:
d[my_key] = {'NULL'my_string: None}
d['test3'] = {'a_key': 'a_value'}
return d
Now, you have 2 branches looking pretty similar, let's factorize this out.
def my_function(my_string,elif my_key):
d != {'test' + str(i)'test3': {}
for i in range(3)}
d[my_key] = {my_string if my_string else 'NULL': None}
d['test3'] = {'a_key': 'a_value'}
return d
Is this as good as it can be ? I think so but I might be wrong.