Python program to convert string to the dictionary.

In this python dictionary program, we will convert string to the dictionary.

Steps to solve the program
  1. Take a string as input in the given format.
  2. First split the string on then, split the string on =.
  3. Then convert it to the dictionary using dict().
  4. Print the output.
				
					str1 = "Apr=April; Mar=March"
dictionary = dict(subString.split("=") 
                  for subString in str1.split(";"))

print(dictionary)
				
			

Output :

				
					{'Apr': 'April', ' Mar': 'March'}
				
			

convert a list of Tuples into a dictionary

convert a matrix into a dictionary.

Leave a Comment