- 3
Help
Can you help me ...i dont know how to write pythone code to count aspecfic name in text in file and how much time it is take to finish
9 Respostas
+ 1
I promise to give you code as soon as you start learning python and show us code. But now I have no exams
+ 10
Rana Saleh ,
i assume that this text file is already existing: (i only talk in general terms)
âȘïžcreate a counter variable
âȘïžopen the txt file in read mode
âȘïžread the content line by line
âȘïž check if the required name exists in the current line
âȘïžif yes: increment the counter by 1
âȘïžwhen all lines are read, the counter contains the number of times the name occures in the file
âȘïžclose the file
+ 6
Rana Saleh ,
please don't ask the community to do this job for you. to get ready codes does not really help you to progress in learning and it does not develop your problem solving ability. as you have joined sololearn just some hours ago, it looks like this is a homework or a challenge like this.
thanks for your understanding!
+ 1
you can use count method to read how many times a word appears in a file and timeit package for measuring how much time it takes.
0
I have 19 file that have in it repeated name which is.MOHAMMAD.i want python code to count how many times it repeated and how much time spend system to find it.
0
I think we can use loop and function and threading
0
Thank you
0
Rana Saleh
import glob & from collections import Counter & import re
Create a variable for your folder path
Assign Counter() to a variable
Using glob creat a variable for a file path
Loop for files in the file path
Use re.findall(r"\bMOHAMMAD\b") then you count it .
For Execution time you can import time and use time.process_time() .
I am not a teacher đ I donât know how to explain something in a clearly way .
- 3
Give me the codei dont know how to write it..i want to learn python soon ..but i have exams now .