Python program to create a dictionary from a string.

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

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

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

Output :

				
					{'s': 2, 'q': 1, 'a': 1, 't': 1, 'o': 2, 'l': 1}
				
			

display different combinations of letters from dictionary values.

print the given dictionary in the form of tables.

Leave a Comment