Q. Write a Python program to create a dictionary from a string.

Note: Track the count of the letters from the string.
Sample string :  'w3resource'
Expected output : {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}


Answer :-


string = input( "Enter a String :-" )
dic = {}

for i in string :
    dic [i] = string.count(i)
print("Dictionary :-",dic)


Output :-

Enter a String :-PathWalla
Dictionary :- {'P': 1, 'a': 3, 't': 1, 'h': 1, 'W': 1, 'l': 2}
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post