+ 1
Write a python program to find string,charecters,words and sentence in a text file contains 5000 lines of sentence.
26 Respuestas
+ 6
Regex will manage it nicely.
You can check the code now, I updated it. You just need to assign re.findall to a variable. This will be a list of sentences, so you can check its length to see the number of sentences found.
+ 8
@RUDRESH
Here's how. Either by str.split() or by using regex module. Notice the difference in precision.
https://code.sololearn.com/cbmdTeEar96f/?ref=app
+ 7
You will need regex for this. Check out 're' library and its documentation, it's really powerful:
https://docs.python.org/3/library/re.html
+ 6
Depends what you define as 'sentence'. Any character plus whitespaces string between two dots? Will that be enough for a definition?
+ 5
Check a few replies back or see here:
https://code.sololearn.com/cbmdTeEar96f/?ref=app
+ 5
a is just a variable to which I assigned a docstring. You can open() a file and .read() it, in order to look for sentences in it.
+ 5
@yuri Yes, it might work better for matching, indeed. Won't dispose of the line breaks before the beginnings of the sentences though :)
+ 3
@Kuba Siekierzynski
Works fine. ☺
+ 1
fname = input("Enter file name")
num_words = 0
chars = 0
with open(fname,'r')as f:
for line in f:
words = lines split()
num_words +=len(words)
chars = chars+len(line)
print (num_words)
print (chars)
+ 1
This d answer for only words & characters.i dnt knw the code for sentence & string..if anyone know thn plz suggest me..
+ 1
there are several typos, indentations, break operator missing.
import os.path
text = """Hi , Fisrt line
fdsgd fgfdkg sdg sdf sdfg -> voidvoid <- sdf kkds
dfsdf
sdf sdf df.
fsdfsd sfd sgojhoptrye -> void <- y ytryrthdfdfs re re ewr gfdsfg r
rtert . F rtret ret dsfgedr
"""
my_file = 'text2.txt'
my_string ='void'
infile = open(my_file,"w")
infile.write (text)
infile.close()
infile = open(my_file,"r")
numlines =0
found =0
for line in infile:
print (line)
numlines+=1
while 1:
str_found_at = line.find(my_string)
if str_found_at == -1:
break
else:
found+=1
line = line[str_found_at+len(my_string):]
infile.close()
print ("%s was found %i times in %i lines" %(my_string,found,numlines))
+ 1
i know, but I need something to test your code at SL.
+ 1
my does
0
it works @ kuba??
0
can som1 give me d code??..
0
Google regex.
No program necessary.
0
how to get sentence separated
0
it is a big text file how can i split it bt commas(,).
so how to count that how many no of sentence in the text file?? this my questions..
0
where u update
0
how can i use some some files & wht z role of a here?