Last active
May 2, 2019 08:36
-
-
Save protorob/863b226ec4a7674a02394d66de9b969d to your computer and use it in GitHub Desktop.
Python scrypt for finding pairs of words that behave in curious ways
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
#inserire il file del vocabolario | |
words = open("zingarelli.txt", "r") | |
# cambiare questo valore per stabilire il numero di lettere delle parole (dev'essere un numero % 2 = 0) | |
maxlenght = 6 | |
wordarray = [] | |
for word in words: | |
if len(word) == maxlenght + 1: | |
#append the maxlenght letter word to the array | |
wordarray.append(word.strip()) | |
# we don't need the file anymore | |
words.close() | |
first_half = int(maxlenght / 2) | |
#nome del file di output | |
outputfile = open('results_6.txt', 'w') | |
for term_1 in wordarray: | |
w1_a = term_1[0:first_half] | |
w1_b = term_1[first_half:] | |
for term_b in wordarray: | |
w2_a = term_b[0:first_half] | |
w2_b = term_b[first_half:] | |
pair_1 = w1_a + w1_b | |
pair_2 = w1_a + w2_a | |
pair_3 = w2_a + w2_b | |
pair_4 = w1_b + w2_b | |
if pair_1 == pair_2 and pair_3 == pair_4: | |
print(term_1) | |
outputfile.write(f"{w1_a} | {w1_b}\n") | |
outputfile.write(f"{w2_a} | {w2_b}\n") | |
outputfile.write(f"------------\r\n") | |
outputfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment