Can someone help me ? Why do there is a problem in line 8 ? Thanks by advance. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help me ? Why do there is a problem in line 8 ? Thanks by advance.

https://code.sololearn.com/cBXmC43P1TSZ/?ref=app

23rd May 2020, 4:31 PM
Bastien GERMANY
Bastien GERMANY - avatar
7 Answers
+ 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.
23rd May 2020, 4:42 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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?
23rd May 2020, 5:00 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
23rd May 2020, 5:34 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Mmm okay I will try. Thanks Kuba Siekierzyński !!
23rd May 2020, 5:44 PM
Bastien GERMANY
Bastien GERMANY - avatar
0
Ow thanks. But to initialize all the variables, have you got an advice ?
23rd May 2020, 4:48 PM
Bastien GERMANY
Bastien GERMANY - avatar
0
And I don't see the problem with indentation.
23rd May 2020, 4:51 PM
Bastien GERMANY
Bastien GERMANY - avatar
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 ?
23rd May 2020, 5:07 PM
Bastien GERMANY
Bastien GERMANY - avatar