- 1
[Unsolved] Hello, I need fast help, I don't know what did I wrong đ, feel free to send full answers (Python)
8 Respostas
+ 7
Quarkom ,
i am quite sure that you are talking about python intermediate tutorial, lessen 10 project 'Letter Counter'
it can be done like: ( not a full answer, but i am sure you can solve the task by yourself)
(letter is a dictionary that has to be declared in advance, char is a variable that will get characters coming from the input string by using a for loop)
âȘïžuse a for loop to iterate over the input string
âȘïžif the current char is in dictionary letters:
use this to "update" the current key/ value pair: letters[char] = letters[char] + 1
âȘïžif the current char is NOT in dictionary letters:
use this to create A NEW key / value pair: letters[char] = 1
after the loop is finished output the dictionary letters
+ 5
Why does the help need to be fast?
I'm not sure what you want to do but mind that while keys in a dictionary are unique, values don't need to be.
Why not just print the whole dictionary? Or print("a:", D.get("a"))?
Here's an overview of dictionary methods:
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_ref_dictionary.asp
+ 2
print(D) works the way you described how you would expect the ouput should be,
cause you already have the values with the get method inside the D value
+ 1
print([*D][0],':',D.get("a")) #this fits there.
0
I'd be grateful for any help đ
0
Lisa it's just a pre code that should help me with whole project
0
Lisa whole code should count how many specific letters are in inputted word, like: hello
Output:
{'h': 1, 'e': 1, 'l': 2, 'o': 1}
0
Okey thank you