Python program to create a dictionary from the string.

In this python dictionary program, we will create a dictionary from the string.

Steps to solve the program
  1. Take a string as input and create an empty dictionary.
  2. Use for loop to iterate over the given string characters.
  3. Add the character as key and its occurrences in the given string as a value using count().
  4. Print the output.
				
					string = "SQAToolss"
dict1 = {}

for char in string:
    dict1[char] = string.count(char)

print(dict1)
				
			

Output :

				
					{'S': 1, 'Q': 1, 'A': 1, 'T': 1, 'o': 2, 'l': 1, 's': 2}
				
			

remove duplicate values from Dictionary.

sort a dictionary in python using keys.

Leave a Comment