File size: 4,885 Bytes
369a349 72004e3 369a349 72004e3 743de20 7702209 743de20 fd73670 a512ba3 9a862cb 01a4713 e78e45b 743de20 8400f85 743de20 e14e2c9 743de20 e14e2c9 743de20 e14e2c9 743de20 e14e2c9 743de20 e14e2c9 c754616 e14e2c9 c754616 e14e2c9 743de20 c754616 743de20 e14e2c9 ba06c9f a512ba3 5abfd64 eb701a9 a512ba3 c754616 743de20 c754616 743de20 f1073c0 008996e f1073c0 c754616 f1073c0 c754616 2ee8757 c754616 2ee8757 c754616 743de20 c754616 2ee8757 c754616 2ee8757 c754616 2ee8757 c754616 72004e3 ba06c9f 72004e3 cc2c129 589f9e5 e78e45b 39bf55d 19457ec 6decdc5 8c1bc7e b43c9d6 289ba75 39bf55d 289ba75 be7efc7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
import streamlit as st
import nltk
import requests
import lxml
import lxml.etree as xml
from nltk.corpus import words
from bs4 import BeautifulSoup as soup
st.markdown("π² Word Games π - 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")
Vowels = "E, A, I, O, U, Y"
Consonants = "R, T, N, S, L, C, D, P, M, H, G, B, F, W, K, V, X, Z, J, Q"
st.write("Vowels: ", Vowels)
st.write("Consonants: ", Consonants)
@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 = 'B').lower()
with b:
second_letter = st.text_input(label="2nd", value = 'A').lower()
with c:
third_letter = st.text_input(label="3rd", value = 'Y').lower()
with d:
fourth_letter = st.text_input(label="4th", value = 'O').lower()
with e:
fifth_letter = st.text_input(label="5th", value = 'U').lower()
with f:
sixth_letter = st.text_input(label="6th", value = '').lower()
with g:
seventh_letter = st.text_input(label="7th", value = '').lower()
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", value = 'ERTHSINTHVCDL')
# Remove remaining choices after exclusions
for character in exclusions:
Vowels = Vowels.replace(character,'')
Consonants = Consonants.replace(character,'')
Vowels = Vowels.replace(' ', '').replace(',','')
Consonants = Consonants.replace(' ', '').replace(',','')
st.write("Vowels Remaining = ", (Vowels))
st.write("Consonants Remaining = ", (Consonants))
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)
tscore2=score2 * 2
tscore3=score3 * 4
tscore4=score4 * 8
tscore5=score5 * 16
tscore6=score6 * 32
tscore7=score7 * 64
totalScore =tscore2 + tscore3 + tscore4 + tscore5 + tscore6 + tscore7
st.markdown("### Words and Scores for Selected Letters")
st.write("Total Score = ", (totalScore))
st.write("Score for 7 letter words = ", (tscore7))
st.write("Words for ",clue7, clue_result7)
st.write("Score for 6 letter words = ", (tscore6))
st.write("Words for ",clue6, clue_result6)
st.write("Score for 5 letter words = ", (tscore5))
st.write("Words for ",clue5, clue_result5)
st.write("Score for 4 letter words = ", (tscore4))
st.write("Words for ",clue4, clue_result4)
st.write("Score for 3 letter words = ", (tscore3))
st.write("Words for ",clue3, clue_result3)
st.write("Score for 2 letter words = ", (tscore2))
st.write("Words for ",clue2, clue_result2)
@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)
|