My current code will list the total number of occurrences of the user input within all the files in the path. How can I edit the code to show me the occurrence of the input for each txt file?
import pathlib name = input('What name are you interested in? ') sex = input('For what sex are you look for? ') path = pathlib.Path("./Names") # adds all files in the 'Names' folder to the path name_list = [] for entry in path.iterdir(): # loops through all the files if entry.is_file(): with open(entry) as f: # will open each file with read permission for line in f: # loop for finding every occurence of 'name' if name in line: if sex in line: current = line.strip().split(',') if current[0] == name: name_list.append(name) # adds all lines with 'name' to a list name_count = name_list.count(name) # counts entries in list print(name, 'has been used a total of', name_count, 'times')