Member-only story
Use Python to Split Sentences into Separate Lines
A guide on how to split sentences into separate lines using Python
I am frequently looking to find problems to solve that may be used in an interview. Although I have not been to any interviews to be a Python programmer, I like to solve problems that will prepare me for that day when I may have to attend an interview.
I have therefore selected a problem that asks the programmer to split sentences into two lines. The pseudocode to solve this problem is cited below:
- Define string, which must have at least two sentences separated by a full stop.
- Define the delimiter, which is a full stop.
- Define a function that will check the string for a full stop. A for loop is created to iterate through the string. If the string does not have a full stop then the character will be added to another string. If the character iterated through has a full stop in it, a new line will be added to the string. Once the string has been completely iterated through, the function will return the new string.
The above code seems simple enough, but it does include some important Python attributes, such as the definition of variables and functions, to include for loops.
More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter and LinkedIn. Join our community Discord.