Search code examples
pythonstringiteratorstring-conversion

Iterate through parts of a string


I have string in the form

[3339:1.6101369,1062:1.5,5751:1.5,6376:1.5,  ...  ]

I want to iterate through the comma separated key-value pairs. What is the best or shortest way to do this?


Solution

  • d = ast.literal_eval('{' + s[1:-1] + '}')