How to Convert String to Dictionary in Python
Here are 3 ways to convert a string to a dictionary in Python: (1) ast.literal_eval(my_string) to convert a string that looks like a dictionary to an actual dictionary: Copy import ast my_string = ‘{1: “blue”, 2: “green”, 3: “red”, 4: “yellow”, 5: “purple”}’ my_dict = ast.literal_eval(my_string) print(my_dict) The result is a dictionary: Examples of different … Read more