Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Weird character appearing after cleaning string

T
TizioCaio95 (470 points)
2 4 6
in HW2 by (470 points)
So I've written some code that allows me to efficiently clean strings but only on some test cases, specifically the "test_hiragana_10_100_50" the process that I go through wildly alters the length of the strings and, occasionally generates the \u escape sequence. I've tried to find out why this happens, but to no avail yet. Does anyone have a clue on why this might occur?

3 Answers

gabriel.bustamante (2540 points)
3 6 20
by (2.5k points)
https://stackoverflow.com/questions/46132917/python-3-and-x-vs-u-vs-u-in-string-encoding-and-why

It could be an issue strictly regarding printing, or conversion from unicode ordinal to a character. Once I had the unicode ordinals I didn't have to convert them back to characters: in this case I would check whether the comparisons between the ordinals still work before continuing.
KilianS (3590 points)
7 10 27
by (3.6k points)
youve tagged that with indexerror, do you get an index error?

also, have you tested your code with smaller strings in idle or in the pythontutor?
T
TizioCaio95 (470 points)
2 4 6
by (470 points)
I do get an Index Error, since the strings end up being of different length, when I loop over them I eventually run out
KilianS (3590 points)
7 10 27
by (3.6k points)
did you run your code on a smaller sample in idle to see what it gives you? maybe it just doesnt put out the spaces
gianluca5539 (9820 points)
4 6 44
by (9.8k points)
If you cycle through all the elements, it could be that it alters and corrupts some of the characters.

There is a better way to remove a character from a string, think about substituting it with "another one".

Hope you got what I'm trying to point you towards