Converting Strings into Python Dictionaries

To convert a string into python dictionary is not at all difficult all you have to do is to

import ast

a_string=u"{1: 'FA-1', 2: 'FA-2', 3: 'SA-1', 4: 'FA-3', 5: 'FA-4', 6: 'SA-2'}"

a_python_dictionary=ast.literal_eval(a_string)
Advertisements

5 thoughts on “Converting Strings into Python Dictionaries

    • I am not too sure if I am getting your query right but if you are referring to this a_string=u”{1: ‘FA-1’, 2: ‘FA-2’, 3: ‘SA-1’, 4: ‘FA-3’, 5: ‘FA-4’, 6: ‘SA-2’}” then its a very simple matter in python.

      • No no brother. I am not asking about the code. I am asking about the design. What is the html code behind. What kind of tag you have used to write the codes in between. If I check your Source, I can find

        import ast
        a_string=u"{1: 'FA-1', 2: 'FA-2', 3: 'SA-1', 4: 'FA-3', 5: 'FA-4', 6: 'SA-2'}"
        a_python_dictionary=ast.literal_eval(a_string)

        So from where you got this html code.

  1. ohh that its not a problem at all just use [ s ou rceco de][/s our ce code] “and write your code in between without any space in the tags I had to add those spaces to for escaping

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s