Last active
October 9, 2022 13:27
-
-
Save marccane/378be236da18d627e1f3e4db95c1b330 to your computer and use it in GitHub Desktop.
This script prints all the words from the given dictionary file that can be written with a single hand in a spanish qwerty layout keyboard
This file contains 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
#!/bin/python3 | |
#This script prints all the words from the given dictionary file that can be written with a single hand in a (spanish) qwerty layout keyboard (using only half of the keyboard) | |
#The dictionary file used (ca.dic) used has been extracted from the open office ca.3.0.5.oxt dictionary file (which is just a zip file) | |
#Requisites: python-unidecode | |
#Parameters | |
minimumWordLength = 3 | |
import sys | |
import unidecode #yay -S python-unidecode | |
if len(sys.argv) != 2: | |
print("The dictionary file parameter is required") | |
exit(0) | |
f = open(sys.argv[1]) | |
leftHandStr = "qwertasdfgzxcvb" | |
rightHandStr = "yuiophjklñnmç-" | |
leftHandSet = {leftHandStr[0]} | |
rightHandSet = {rightHandStr[0]} | |
leftHandWords = [] | |
rightHandWords = [] | |
for c in leftHandStr: | |
leftHandSet.add(c) | |
for c in rightHandStr: | |
rightHandSet.add(c) | |
for z in f: | |
l = z.strip().lower().split("/")[0] | |
l = unidecode.unidecode(l) | |
if all((c in leftHandSet) for c in l): | |
if l not in leftHandWords and len(l) >= minimumWordLength: | |
leftHandWords.append(l) | |
elif all(c in rightHandSet for c in l): | |
if l not in rightHandWords and len(l) >= minimumWordLength: | |
rightHandWords.append(l) | |
leftHandWords.sort() | |
rightHandWords.sort() | |
print("Left hand words ({}):".format(len(leftHandWords))) | |
for w in leftHandWords: | |
print(w) | |
print() | |
print("Right hand words ({}):".format(len(rightHandWords))) | |
for w in rightHandWords: | |
print(w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment