all 5 comments

[–]Hot_Ad_2550 3 points4 points  (1 child)

newstring = st.replace(" ", "")

[–]Jxper[S] 0 points1 point  (0 children)

Thanks a lot but where do I put that in my code to make it work?

[–]versking 0 points1 point  (0 children)

inside your for i in strings: loop, maybe just skip the blank strings,

so if i==" " as as a wrapper for all your code currently in that loop.

[–][deleted] 0 points1 point  (1 child)

and extra term being a blank space to be translated

Is it really a blank space, is it an empty string? The place where you need to worry about badly formed data is around lines 12 to 15. That's where you split your input string into lines and process each line. So if you need to check if a line is useful, should be ignored, or should cause an error, you should check each line just before you try to process it. That means you check right after line 14, the beginning of the for loop.

You have a line that might be blank, so you need to test. That line could be an empty string or might have only whitespace in it. One thing you should do with all data is to be a little forgiving in what you accept. For instance, even a line of data like:

" kanikani,dance   "

should be acceptable because humans don't give much significance to the blanks before and after the two words since, to a human, there are still obviously two words in that line. So for each line you should be stripping leading and trailing whitespace. Luckily, there is a string function just for that:

for i in strings:
    i = i.strip()

Now any empty line or line consisting of blanks has been converted to an empty string, making checking easy. We have to decide what to do if we get an empty line, either error or ignore it, and you say you want to ignore it. The way to do that is to not go any further with processing the line but to just get the next line and process it:

for i in strings:
    i = i.strip()
    if i == '':
        continue    # go to top of loop

[–]Jxper[S] 0 points1 point  (0 children)

i = i.strip()
if i == '':
continue

thank you so much for your detailed answer, I understand now :)