How to convert dictionary into string

python, string

Solution

To convert from the dict to the string in the format you want:

''.join('{}{}'.format(key, val) for key, val in adict.items())

if you want them alphabetically ordered by key:

''.join('{}{}'.format(key, val) for key, val in sorted(adict.items()))

Problem

I'm trying to use the solution provided here Instead of getting a dictionary, how can I get a string with the same output i.e. character followed by the number of occurrences Example:d2m2e2s3

Original source

Related problems