Python Forum
Fequency of letters with dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fequency of letters with dictionary
#1
Hello guys! So I have been trying to fix this but I havent made it yet, so if someone knows please give me a hand!

so the instructions are this:

" Enter a text and count the number of occurrences of letters and punctuation symbols (except spaces) to form a dictionary of "Number-Character List". That is, the key of the dictionary is the number of occurrences, and the value is a list of letters and punctuation symbols with the same occurrence times."

For example, the dictionary corresponding to "apple" is {1:['a','l','e'], and 2:['p']}.

right now I have done this:
test_str=input('Enter some text:' )
res={}
for keys in test_str:
    res[keys]=res.get(keys,0)+1
print('The "Freq-chars" dictionary is: \n' + str(res))
and this is my output:
Output:
Enter some text:saudi nuclear program accelerates, raising tensions in a volatile region The "Freq-chars" dictionary is: {'s': 5, 'a': 8, 'u': 2, 'd': 1, 'i': 7, ' ': 9, 'n': 6, 'c': 3, 'l': 4, 'e': 7, 'r': 6, 'p': 1, 'o': 4, 'g': 3, 'm': 1, 't': 3, ',': 1, 'v': 1}
but what the output should look like is:
[Image: download?verifier=Sm16TMkWU5HBqjEOcoe1Y2...IBq&wrap=1]
the thing here is that mine right now is (letter:times) but I should have (time,letter) for example: 1:['a','t','c'] instead of 'a':1 , 't':1, etc.

Thank you so much for your help and comments! Heart
Reply


Messages In This Thread
Fequency of letters with dictionary - by Jen_Sophia - Apr-09-2019, 04:15 PM
RE: Fequency of letters with dictionary - by Yoriz - Apr-09-2019, 07:54 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020