Any legit way for using "if" statements and "for" loop while creating a dictionary in Python? -
report['conditions'] += [ { "name": cond, "birad": br, "findings": [ { "name": f, **if f == 'mass':** "parameters": [ { "name": iter_params_mass[0], "value": create_rep(iter_params_mass, row, f, r)[0] },{...} ] } ] }]
i have strict structure bson file, instead of creating manually, use if statement , for loop (if possible), because can have more 1 pair of name-value in parameters. efficient way it? thanks! i'm using python 3.6.0
sudo code how can done:
if f == 'mass': # construct parameters loop maybe: parameters = {key: value (key, value) in [('a','b'),('c','d')]} # parameters = {'a': 'b', 'c': 'd'} else: parameters = {key: value (key, value) in [('b','a'),('d','c')]}
then use parameters create final bson dict
report['conditions'] += [{"name": cond, "birad": br, "findings": [ {"name": f, "parameters": parameters
Comments
Post a Comment