Apr-09-2019, 04:15 PM
(This post was last modified: Apr-09-2019, 04:15 PM by Jen_Sophia.)
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:
and this is my output:
![[Image: download?verifier=Sm16TMkWU5HBqjEOcoe1Y2...IBq&wrap=1]](https://elearning.fudan.edu.cn/courses/11141/files/23548/download?verifier=Sm16TMkWU5HBqjEOcoe1Y2aJXdRDWlz6Du3JPIBq&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!
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:
1 2 3 4 5 |
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)) |
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: 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!
