Code:

```
'''
Program to Compress a string using Dictonaries.

Input samle--> 'AAAABBBBCCCCDDDDaa'
output sample--> 'A4B4C4D4a2'

'''
# Function declaration
def string_compression(str):
    d = {}
    x = []

    # Generating Key-Value pair for entire string
    for i in str:
        if i not in d.keys():
            d[i] = 1
        else:
            d[i] = d[i] + 1

    # Copying Key Value Pairs in a list
    for key,value in d.items():
        x.append(key)
        x.append(value)

    # Printing a Cocktail list of Strings and Integers
    print(x)

    # Converting Integers in list x to Strings and Joining them
    for i in x[1::2]:
        x[i] = str(x[i])
    print(''.join(x))
    #print(''.join(map(str, x)))

y = 'AAAABBBBCCCCDDDDaa'
string_compression(y) # Function Call

```

Output:

```
['A', 4, 'B', 4, 'C', 4, 'D', 4, 'a', 2]

Traceback (most recent call last):
  File "string_compression.py", line 36, in <module>
    string_compression(y) # Function Call
  File "string_compression.py", line 30, in string_compression
    x[i] = str(x[i])
TypeError: 'str' object is not callable

```

I'm able to print x as list,
But I'm unable to print the list in string format.

Also I tried all the possible combinations of solutions as per my previous post:
[Converting list of Integers and Strings to purely a string](https://stackoverflow.com/questions/55452661/converting-a-list-of-integers-and-strings-to-purely-a-string/55452843#55452843)

But The link's solutions are working only if I try to run the code in a new file taking only 2 lines of code as:

`x = ['A', 4, 'B', 4, 'C', 4, 'D', 4, 'a', 2]
print(''.join(map(str, x)))` 

Why are any of the methods not working here in this above code? Any concept which I'm lagging?