0

how to add letters as keys in an empty dic when the input is a text

30th Jun 2022, 7:16 PM
Maria imram
Maria imram - avatar
7 odpowiedzi
+ 2
Can you please give an example? Like, what is the dictionary supposed to look like in respect to a given text?
30th Jun 2022, 7:31 PM
Lisa
Lisa - avatar
+ 2
You could approach it like this: * create an empty dict and iterate the string by letter (for-loop) * for each letter, check if it is already in the dict * if not, add it as key to the dict with the value 1 * if yes, update the value and increase if by one
30th Jun 2022, 7:44 PM
Lisa
Lisa - avatar
+ 1
Follow the approach that I have outlined. Go through it step by step. You can show us your updated code and we'll check on it.
30th Jun 2022, 8:02 PM
Lisa
Lisa - avatar
+ 1
For new users the messaging feature unlocks after a few weeks, you just need to wait a little longer. :) Post in this thread, so everyone can help you!
30th Jun 2022, 8:34 PM
Lisa
Lisa - avatar
0
like if the input is "hello" and i want the output to be like this {h:1,e:2,l:2,o:1} i want to know how many times each letter appears
30th Jun 2022, 7:41 PM
Maria imram
Maria imram - avatar
0
why can't i send u a message
30th Jun 2022, 8:17 PM
Maria imram
Maria imram - avatar
- 2
can u complete this code for me text=input() dict={}
30th Jun 2022, 7:54 PM
Maria imram
Maria imram - avatar