-
-
Save joeflack4/c784a3dbdaf6d79e18a7f9bda5d3aba8 to your computer and use it in GitHub Desktop.
Revisions
-
joeflack4 created this gist
May 31, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ """Count file name appearances""" import os from collections import defaultdict from glob import glob # Path to the Desktop desktop_path = os.path.expanduser("~/Desktop") # Filenames filenames = glob(os.path.join(desktop_path, "*.txt")) # Print print('Analyzing which files changed in various build PRs, and how many times they appeared in multiple PRs') print('Reading: ' + ','.join(os.path.basename(x) for x in filenames) + '\n') # Initialize a defaultdict to store the counts line_counts = defaultdict(int) # Read each file and count the occurrences of each line for filename in filenames: file_path = os.path.join(desktop_path, filename) with open(file_path, 'r') as file: for line in file: line = line.strip() # Remove any leading/trailing whitespace line_counts[line] += 1 # Convert defaultdict to a regular dictionary (optional) line_counts = dict(line_counts) grouped_by_n_times = {} for k, v in line_counts.items(): if v not in grouped_by_n_times: grouped_by_n_times[v] = [] grouped_by_n_times[v].append(k) # Print report print('Results: ') print('Each number header represents the number of times a file appeared in multiple PRs') highest_count = max(grouped_by_n_times.keys()) i = highest_count while i > 0: v = grouped_by_n_times.get(i, []) if v: print(str(i) + ' -------------------') for filename in v: print(filename) print('') i -= 1