Skip to content
Advertisement

Python fails to recognize a digit

I have an input file such as this and the program removes everything but the hindi text.

JavaScript

Here is my program

JavaScript

and the expected output is below

JavaScript

However, my program doesn’t recognize the first line digit, and instead it returns

JavaScript

Why does this program doesn’t recognize the digit when I specifically wrote 1 or “1”?

Advertisement

Answer

Using regex we can create a simple expression that covers the three cases that you want to ignore:

  1. timestamp line
  2. number line
  3. empty line

From there we can use python’s built-in filter method to filter out all of the undesired lines, and use the filter results as the lines to write.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement