Weird character appearing after cleaning string

T
TizioCaio95 (470 points)
2 4 6
asked Nov 3, 2021 in HW2 by TizioCaio95 (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 (2490 points)
3 5 20
answered Nov 3, 2021 by gabriel.bustamante (2,490 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 (3460 points)
5 8 27
answered Nov 3, 2021 by KilianS (3,460 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
commented Nov 3, 2021 by TizioCaio95 (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 (3460 points)
5 8 27
commented Nov 3, 2021 by KilianS (3,460 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 (9710 points)
2 4 42
answered Nov 3, 2021 by gianluca5539 (9,710 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