import streamlit as st import nltk from nltk.corpus import words st.title("🐲 Word Games 🐉") st.markdown("Enter two to seven letters to get a high score of as many words as you can of that length. Leave a letter blank to confine word search to a smaller number of letters.") st.markdown("Letters in Descending Frequency and Proportion in Words") st.markdown("Vowels: E, A, I, O, U, Y") st.markdown("Consonants: R, T, N, S, L, C, D, P, M, H, G, B, F, W, K, V, X, Z, J, Q") @st.cache # cache download processes so they only execute once with same inputs def download(): nltk.download('words') download() [a,b,c,d,e,f,g] = st.columns(7) with a: first_letter = st.text_input(label="1st",value = 's') with b: second_letter = st.text_input(label="2nd", value = 'e') with c: third_letter = st.text_input(label="3rd", value = 'a') with d: fourth_letter = st.text_input(label="4th", value = 'l') with e: fifth_letter = st.text_input(label="5th", value = 'o') with f: sixth_letter = st.text_input(label="6th", value = 't') with g: seventh_letter = st.text_input(label="7th", value = 'c') clue2 = first_letter+second_letter clue3 = first_letter+second_letter+third_letter clue4 = first_letter+second_letter+third_letter+fourth_letter clue5 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter clue6 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter+sixth_letter clue7 = first_letter+second_letter+third_letter+fourth_letter+fifth_letter+sixth_letter+seventh_letter exclusions = st.text_input(label="exclusions") clue_result2 = [] clue_result3 = [] clue_result4 = [] clue_result5 = [] clue_result6 = [] clue_result7 = [] two_letters = [word for word in words.words() if len(word)==2 ] three_letters = [word for word in words.words() if len(word)==3 ] four_letters = [word for word in words.words() if len(word)==4 ] five_letters = [word for word in words.words() if len(word)==5 ] six_letters = [word for word in words.words() if len(word)==6 ] seven_letters = [word for word in words.words() if len(word)==7 ] #score score2=0 score3=0 score4=0 score5=0 score6=0 score7=0 for word in two_letters: if all(c in word for c in clue2) and not any(c in word for c in exclusions): score2+=1 clue_result2.append(word) for word in three_letters: if all(c in word for c in clue3) and not any(c in word for c in exclusions): score3+=1 clue_result3.append(word) for word in four_letters: if all(c in word for c in clue4) and not any(c in word for c in exclusions): score4+=1 clue_result4.append(word) for word in five_letters: if all(c in word for c in clue5) and not any(c in word for c in exclusions): score5+=1 clue_result5.append(word) for word in six_letters: if all(c in word for c in clue6) and not any(c in word for c in exclusions): score6+=1 clue_result6.append(word) for word in seven_letters: if all(c in word for c in clue7) and not any(c in word for c in exclusions): score7+=1 clue_result7.append(word) st.markdown("### Words and Scores for Selected Letters") st.write("Words for ",clue2, clue_result2) tscore2=score2 * 2 st.write("Score for 2 letter words = ", (tscore2)) st.write("Words for ",clue3, clue_result3) tscore3=score3 * 4 st.write("Score for 3 letter words = ", (tscore3)) st.write("Words for ",clue4, clue_result4) tscore4=score4 * 8 st.write("Score for 4 letter words = ", (tscore4)) st.write("Words for ",clue5, clue_result5) tscore5=score5 * 16 st.write("Score for 5 letter words = ", (tscore5)) st.write("Words for ",clue6, clue_result6) tscore6=score6 * 32 st.write("Score for 6 letter words = ", (tscore6)) st.write("Words for ",clue7, clue_result7) tscore7=score7 * 64 st.write("Score for 7 letter words = ", (tscore7)) totalScore =tscore2 + tscore3 + tscore4 + tscore5 + tscore6 + tscore7 st.write("Total Score = ", (totalScore)) import requests from bs4 import BeautifulSoup as soup import lxml import lxml.etree as xml @st.cache # cache download processes so they only execute once with same inputs def define(word): url = f'https://www.dictionary.com/browse/{word}?s=t' r=requests.get(url) s = soup(r.content, features="lxml") for tag in s.find_all("meta"): if tag.get("property", None) == "og:description": content = tag.get("content", None) return content for word in clue_result7: content = define(word) st.write(content)