Question: i have a text file of numbers like so 

**text.file**
`'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9`
i would like to convert this to an array like so :

`myary= {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}`
but i want the **keys** to be a **string** and the **values** to be **integer**

i think i am able to get all of this as a string but that is not what i want 
i want it to be seprate

Answer: 
using `ast.literal_eval`

```
import ast
txt = "'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9"
print (ast.literal_eval('{' + txt + '}'))
#{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

```
If you don't want to use literal\_eval

```
str="'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9"
print({x[0].replace("'", ""):int(x[1]) for x in [y.split(': ') for y in [z for z in str.split(',')]] })
#{'2': 2, '7': 7, '8': 8, '4': 4, '1': 1, '9': 9, '3': 3, '6': 6, '5': 5}

```