Skip to content

Commit

Permalink
runnable, new name
Browse files Browse the repository at this point in the history
  • Loading branch information
ontanj committed Mar 11, 2020
1 parent 7bf711a commit 5b01178
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions propositions.py → wordfinder
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
#! /usr/bin/env python3

import sys
import re
import urllib.request as urlr
import urllib
from html.parser import HTMLParser

class SAOLWordFinder:
class WordFinder:

def __init__(self, pattern, verbose=False):
self.pattern = pattern
Expand Down Expand Up @@ -170,21 +169,18 @@ def add_words(self, words):
self.calculate_progress(word[0])
self.words.append(word)

def prop(word):
consonants = "bcdfghjklmnpqrstvwxz"
vocals = "aeiouyåäö"
letters = "abcdefghijklmnopqrstuvwxyzåäö"
propositions = [""]
for letter in word:
if letter == '@':
propositions = [former + new for former in propositions for new in vocals]
elif letter == '$':
propositions = [former + new for former in propositions for new in consonants]
elif letter == '£':
propositions = [former + new for former in propositions for new in letters]
else:
propositions = [former + letter for former in propositions]
return propositions
def prop(self):
propositions = [""]
for letter in self.pattern:
if letter == '@':
propositions = [former + new for former in propositions for new in self.vocals]
elif letter == '$':
propositions = [former + new for former in propositions for new in self.consonants]
elif letter == '£':
propositions = [former + new for former in propositions for new in self.letters]
else:
propositions = [former + letter for former in propositions]
return propositions

if __name__ == "__main__":
word = None
Expand All @@ -207,14 +203,14 @@ def prop(word):
else:
print(f"Löser dina korsordsbekymmer.\n")

wd = SAOLWordFinder(word, verbose=True)
wd = WordFinder(word, verbose=True)
if print_props:
dont_print = "n"
if wd.no_of_props >= 1000:
print(f'Det finns {wd.no_of_props} möjligheter.\n')
dont_print = input("Vill du skippa att skriva ut dem? [Y/n]")
if dont_print == "n":
props = prop(word)
props = wd.prop()
string = f"Följande möjligheter finns:\n"
for p in props:
string += p + ", "
Expand Down

0 comments on commit 5b01178

Please sign in to comment.