Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a program in python3.

If your
input:
I am a Student of Nalanda Institute of technology.And I am a Good boy.
Output:
I am a of technology.And am a boy.

Means your First word should be available in out put but starting a word from capital letter(Student) should not be show in your output.But after full stop First word must be in your output.

But you have to read the text from a text file.

What I have tried:

Python
import os

os.chdir("C:/Users/Biswajit Sahu/Desktop/Tickets/")

file = open('bisu.txt','r')
lines = file.readlines()
for line in lines:
    print(line)
    
list_1 = []
list_2 = []
list_1 = line.split()
for i in list_1:
    if i.istitle():
        pass
    else:
        list_2.append(i)
result = ' '.join(list_2)
print('*'*120)
print(result)
f.close()



My text file input
I biswajit Babuni sahu. I ramchandra Sahu pradhan.
************************************************************************************************************************
output
biswajit sahu. ramchandra pradhan.
Posted
Updated 14-Jan-19 21:55pm
v3
Comments
Richard MacCutchan 10-Jan-19 12:34pm    
You forgot about the first word in each sentence. Start by splitting at full stops, which will then allow you to extract the first word before testing for the other capitalised words.
Member 14053678 15-Jan-19 0:19am    
I am not unable to make a separate list of full stop in the sentence.
Richard MacCutchan 15-Jan-19 5:15am    
Why not?

1 solution

Try
Python
line = "I biswajit Babuni sahu. I ramchandra Sahu pradhan."
words = line.split()
was_dot = True
results = []
for word in words:
  if was_dot or not word.istitle():
    results.append(word)
  was_dot = word.endswith('.')
print(' '.join(results))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900