Python - Print Each Sentence On New Line

2024/10/15 4:19:09

Per the subject, I'm trying to print each sentence in a string on a new line. With the current code and output shown below, what's the syntax to return "Correct Output" shown below?

Code

sentence = 'I am sorry Dave. I cannot let you do that.'def format_sentence(sentence):sentenceSplit = sentence.split(".")for s in sentenceSplit:print s + "."

Output

I am sorry Dave.I cannot let you do that.
.
None

Correct Output

I am sorry Dave.
I cannot let you do that.   
Answer

You can do this :

def format_sentence(sentence) :sentenceSplit = filter(None, sentence.split("."))for s in sentenceSplit :print s.strip() + "."
https://en.xdnf.cn/q/117873.html

Related Q&A

pyinstaller struct.error: unpack requires a bytes object of length 16 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Getting the quarter where recession start and recession ends along with the quarter of minimum gdp

Quarter: GDP: GDP change: change 1999q3 9 -- ------ 1999q4 10 1 increase 2000q1 9 -1 decline 2000q2 8 -1 de…

Inherit view and adding fields

I want to add my 2 fields boatlenght and fuelcapacity under price list in product form view but they are not showing up. What did i miss.<?xml version="1.0" encoding="utf-8"?&g…

Linux and python: Combining multiple wave files to one wave file

I am looking for a way that I can combine multiple wave files into one wave file using python and run it on linux. I dont want to use any add on other than the default shell command line and default py…

How does the in operator determine membership? [duplicate]

This question already has answers here:Set "in" operator: uses equality or identity?(5 answers)Closed 7 years ago.How does the in operator work for Python? In the example below I have two n…

Python Automatically ignore unicode string

Ive been searching to automatically import some files but since Im on Windows i got the unicode error (because of the "C:\Users\..."). Ive been looking to correct this error and found some h…

How to obtain currency rates from this website converter widget python

How can I implement the currency rates on this website and keep the currencies up to date so that i can access them in python from this website and input and output values and currencies types. I need …

Trying to add sums from a csv file in python

I need to add sums of a csv file. The program is a test for a travel reservation system and the file reads like this:availableSTART,reservations,cancellations,availableEND 20,1,0,18I need to subtract r…

Numerical patterns in Python3 [duplicate]

This question already has answers here:How to print without a newline or space(30 answers)Closed 7 years ago.Im fairly new to programming, i have to start learning it for Uni.I have to make a pattern a…

setsockopt before connect for reactor.connectTCP

I have a small python client which needs a setsockopt after create_socket, but before connect. The non-twisted python code is as follows. How can this be expressed in a twisted environment?create_sock…