Adding a string to all keys in dictionary (Python)
Try a dictionary comprehension:
{k+'@d1': v for k, v in d.items()}
In Python 3.6+, you can use f-strings:
{f'{k}@d1': v for k, v in d.items()}
You can use dict
constructor to rebuild the dict, appending file number to the end of each key:
>>> d = {'a': 1, 'b': 2}
>>> file_number = 1
>>> dict(("{}@{}".format(k,file_number),v) for k,v in d.items())
>>> {'a@1': 1, 'b@1': 2}