I am designing a dictionary from a string, but I have noticed that after using 'ast.literal_eval()' on python 2.7, my dictionary sequence changes. The good thing is that the values designated to the keys follow suit. I just wanted to know why it does this. Here is a snippet of my code that should be able to run:
import ast
Medication = ["{'A': 3, 'B': 10, 'C': 0, 'D': 3}"]
print "Medication before ast.literal_eval: ", Medication[0]
print ""
dictionaryDose = ast.literal_eval(Medication[0])
print "Medication after ast.literal_eval: ", Medication[0]
print ""
print "DictionaryDose: ", dictionaryDose
Here is the output:
Medication before ast.literal_eval: {'A': 3, 'B': 10, 'C': 0, 'D': 3}
Medication after ast.literal_eval: {'A': 3, 'B': 10, 'C': 0, 'D': 3}
DictionaryDose: {'A': 3, 'C': 0, 'B': 10, 'D': 3}