Oct-30-2018, 07:01 PM
(Oct-30-2018, 05:57 PM)gonzo620 Wrote: this program is printing a 1 for every occurrence of 'name'. What I want is to print the total number of occurrences 'name' has throughout all the files. What am I missing?
okay I was able to get a little closer to my desired end result.
import pathlib name = input('Enter a name: ') name_list = [] path = pathlib.Path("./Names") for entry in path.iterdir(): if entry.is_file(): with open(entry,'r') as f: for line in f: if name in line: name_list.append(name) name_count = name_list.count(name) print(name_count)
Output:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
I just need the total number printed. I don't need the program to print all the counting