In this python dictionary program, we will convert string to the dictionary.
Steps to solve the program
- Take a string as input in the given format.
- First split the string on ; then, split the string on =.
- Then convert it to the dictionary using dict().
- Print the output.
str1 = "Apr=April; Mar=March"
dictionary = dict(subString.split("=")
for subString in str1.split(";"))
print(dictionary)
Output :
{'Apr': 'April', ' Mar': 'March'}