Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

2nd Aug 2021, 4:23 PM
Rana Saleh
9 Answers
+ 1
I promise to give you code as soon as you start learning python and show us code. But now I have no exams
2nd Aug 2021, 6:08 PM
Shadoff
Shadoff - avatar
+ 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
2nd Aug 2021, 4:26 PM
Lothar
Lothar - avatar
+ 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!
2nd Aug 2021, 4:38 PM
Lothar
Lothar - avatar
+ 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.
2nd Aug 2021, 4:28 PM
Abhay
Abhay - avatar
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.
2nd Aug 2021, 4:30 PM
Rana Saleh
0
I think we can use loop and function and threading
2nd Aug 2021, 4:31 PM
Rana Saleh
0
Thank you
2nd Aug 2021, 4:39 PM
Rana Saleh
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 .
3rd Aug 2021, 9:45 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
- 3
Give me the codei dont know how to write it..i want to learn python soon ..but i have exams now .
2nd Aug 2021, 4:33 PM
Rana Saleh