def test_dict_min_max(self): self.assertListEqual([w for w in self.words if (5 <= len(w) <= 6)], load_dict(self.filename, 5, 6))
def test_dict_max(self): self.assertListEqual([w for w in self.words if len(w) <= 4], load_dict(self.filename, None, 4))
def test_dict_load(self): self.assertListEqual(self.words, load_dict(self.filename))
def test_dict_min(self): self.assertListEqual([w for w in self.words if len(w) >= 5], load_dict(self.filename, 5))
#!/usr/bin/env python from flask import Flask, render_template, request, Response import logging as log import json from pynagram.pynagram import (get_anagrams, load_dict) MAX_INPUT_LEN = 10 log.basicConfig(level=log.DEBUG) log.debug("Caching word list: crosswd.txt") dictionary = load_dict('crosswd.txt') log.debug(f"Loaded {len(dictionary)} words.") app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/anagram', methods=['POST']) def anagram(): string = request.form.get('input') log.info(f"input = [{string}]") string_len = len(string) anagrams = sorted(get_anagrams(string, dictionary, 1, string_len), key=lambda w: (len(w), w)) log.debug(f"Anagram [{string}] has {len(anagrams)} anagrams") return render_template('anagram.html', **{