A dictionary like Dict = {'Key_1': 'Data_1', 'Key_2': 'Data_2', ..., 'Key_n': 'Data_n'}
contains n
keys named in ascending order.
A method like AddNextKey(Dict, NewData)
should determine the last key n
and add a new one n+1
with value NewData
.
If Dict
is empty, the method should append key Key_1
.
I am quite sure that a pythonic solution does not require more than two or three lines of code to achieve this.
Remark: It is not important that the dictionary is ordered. Only the correct next key (n+1) must be appended.
Could anybody give advice?