


either repr(d) or json.dumps(d) will give you something very similar to your existing string, but with proper quotes.īut if you've just got a mess of strings someone else gave you, the easiest thing to do might be to regex it into an actual JSON string so you can parse it: json.loads(re. string1 'subj1 - 10, subj2 - 20, subj3 - 25, subj4 - 14'. So, instead of converting the dictionary to XML string and then saving it to a file, we can directly save the XML formatted data to the file using the xmltodict module.
#PYTHON CONVERT STRING TO DICTIONARY GENERATOR#
First, if you're generating these strings from dictionaries (in Python or almost any other language), you might want to consider generating them in a way that can be easily parse. python pandas django python-3.x numpy list dataframe tensorflow matplotlib dictionary string keras python-2.7 arrays django-models regex pip machine-learning selenium json datetime deep-learning django-rest-framework csv flask loops opencv for-loop function algorithm tkinter scikit-learn jupyter-notebook windows html beautifulsoup sorting scipy. Finally, in the last example we will discuss how generator expressions can be used.
