I'm trying to write some python functions to generate a batch of input files, in which there is, for instance, this block:
***behavior
**energy_phase_1
ef_v 10
**energy_phase_2
ef_v 7.
So far i was using collections.OrderedDict, because order matters in this kind of input file). For instance,if there are two simulations in my batch:
inp_dict['***behavior'] = [ '', '']
inp_dict['**energy_phase_1'] = [ '', '']
inp_dict['**ef_v'] = [ '10', '20']
inp_dict['**energy_phase_2'] = [ '', '']
inp_dict['**ef_v'] = [ '7', '14']
And to write the file I would just do something like:
for s , n in enumerate(sim_list):
......some code...
inp_file.write(' '.join([ key, val[s], '\n' for key, val in inp_dict.items]))
But as you can see, this is not enough, since it there are duplicates key in the dict.
So my question is: is there an ordered dict that allows for duplicate keys? For instance, if there exists dict['key']=1 and dict['key']=2, first call would return 1 and second 2?
Or, is there some clever and simple way to achieve want I want?
Thanks