A
A
Artem2018-02-13 11:48:01
Python
Artem, 2018-02-13 11:48:01

How to format text with python with certain condition?

Welcome all! Please help me with this question:
at the input we have a text file with something like this

"""ELECTION by Alexander Payne & JIM Taylor
  
  Third Draft July 22,1997
  Based on the novels by Tom Perotta
  
  
  EXT. MILLARD HIGH -- DAWN
  
  The school stretches out before us, slumbering in the overcast morning 
  air.
  
  A TEENAGE GIRL'S VOICE -
  
          TRACY (VO) 
      None of this would have happened if Mr. 
      McAllister hadn't meddled the way he 
      did.  He should have just accepted 
      things as they are instead of trying to 
      interfere with destiny.  You see, you 
      can't interfere with destiny.  That's 
      why it's destiny.  And if you try to 
      interfere, the same thing's going to 
      happen anyway, and you'll just suffer."""

The challenge is to use Python to determine a string that is all uppercase, such as "EXT. MILLARD HIGH -- DAWN" (well, it's just -- s.isupper()), then check if the next string after that one is empty. If yes, then everything is OK, but if not, as in the case of the "TRACY (VO)" line, then you need to add this very empty line...
Actually, my problem is that I can't come up with an algorithm for implementing such a task. As I understand it, you need to break the text into lines and loop through the list of lines. But how to set a check for an empty string for string n + 1, if we are on string n ...
Thanks to those who responded in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question