Python Forum
Python - Limit Sentence Length to 10 Words - Text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Limit Sentence Length to 10 Words - Text file
#1
I am trying to limit each sentence to 10 words


file = open("a.txt","r") 
content = file.read()
file.close()

file_out = open("out.txt","w+") 

for i in range(len(content)):
    file_out.write(content[i])

   

    if (i + 1).join(i.split()[:10]):
        

         file_out.write('\n')
file_out.close()
what would be the correct syntax?



:)


Python newbie trying to learn the ropes
Reply


Messages In This Thread
Python - Limit Sentence Length to 10 Words - Text file - by dj99 - Jul-21-2018, 01:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace a text/word in docx file using Python Devan 4 2,851 Oct-17-2023, 06:03 PM
Last Post: Devan
  Form that puts diacritics on the words in the text Melcu54 13 1,383 Aug-22-2023, 07:07 AM
Last Post: Pedroski55
  save values permanently in python (perhaps not in a text file)? flash77 8 1,120 Jul-07-2023, 05:44 PM
Last Post: flash77
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,064 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  python-docx regex : Browse the found words in turn from top to bottom Tmagpy 0 1,489 Jun-27-2022, 08:45 AM
Last Post: Tmagpy
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,576 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,842 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Can I Limit Value used by python pajd 9 2,097 Feb-10-2022, 09:54 PM
Last Post: pajd
  Extract a string between 2 words from a text file OscarBoots 2 1,827 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  getting the length of a file in a loop sgcgrif33 1 1,695 Aug-23-2021, 05:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020