Created
December 13, 2022 18:57
-
-
Save dmd/2aecc080520f4b30ebb7acfc0ae25981 to your computer and use it in GitHub Desktop.
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 characters
import itertools | |
# Open the files in read-only mode | |
with open('PATTERNS.txt', 'r') as patterns_file, open('TEXT.txt', 'r') as text_file: | |
# Read the patterns from the file and store them in a list | |
patterns = patterns_file.read().splitlines() | |
# Create a dictionary to store the counts for each pair of patterns | |
pattern_pair_counts = {} | |
# Loop through each line in the text file | |
for line in text_file: | |
# Loop through each combination of two patterns | |
for pattern1, pattern2 in itertools.combinations(patterns, 2): | |
# Check if the line contains both patterns | |
if pattern1 in line and pattern2 in line: | |
# If the pair of patterns is not in the dictionary, add it with a count of 1 | |
if (pattern1, pattern2) not in pattern_pair_counts: | |
pattern_pair_counts[(pattern1, pattern2)] = 1 | |
# Otherwise, increment the count for the pair of patterns | |
else: | |
pattern_pair_counts[(pattern1, pattern2)] += 1 | |
# Print the counts for each pair of patterns | |
for pattern_pair, count in pattern_pair_counts.items(): | |
print(f'{pattern_pair}: {count}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment