+ 1
Can someone help me ? Why do there is a problem in line 8 ? Thanks by advance.
7 Réponses
+ 2
The text must have been copied from somewhere and contains illegal whitespaces. Use the backspace and edit the code once again and set a proper indentation in lines 8 and 9.
Still, the code won't work, as there will be a problem with the d dictionary declaration. You have put strings as keys, which is fine, but the values are referring to variables, which have not been declared before.
+ 2
Bastien GERMANY Line 9 has similar problems as line 8, there are some whitespaces - just delete those and put normal spaces in place.
As for the dict -- what is it supposed to do, actually? You want it to point to what kind of values?
+ 1
Bastien GERMANY I think you don't utilize the power of the dictionary here. It is exactly the type of collection you need here, but you don't have to boil the ocean by initializing everything.
Just create an empty dictionary and when iterating through the text, for each letter check if there is already a key equal to it. If not, add it and assign value 1 to it. But if there already is, just increment by one.
You will end up with a dictionary with key-value pairs, where keys will be the letters and values will be their frequencies.
+ 1
Mmm okay I will try. Thanks Kuba Siekierzyński !!
0
Ow thanks. But to initialize all the variables, have you got an advice ?
0
And I don't see the problem with indentation.
0
Ok that's great for the indentation. But for the dict, I wanted to associate each letter to a variable which can be incremented. But indeed, I didn't initialize them because they are too much, I thought their default value would be 0. Have you got a solution ?