File size: 1,122 Bytes
8350e03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import itertools
from nltk.corpus import wordnet

def get_synonyms(word):
    synonyms = set()
    for syn in wordnet.synsets(word):
        for lemma in syn.lemmas():
            synonyms.add(lemma.name())
    return list(synonyms)

def generate_words(letters, length=None):
    permutations = set()
    for i in range(1, len(letters) + 1):
        for p in itertools.permutations(letters, i):
            word = "".join(p)
            if length is None or len(word) == length:
                permutations.add(word)
    return permutations

st.title("Scrabble Helper")

letters = st.text_input("Enter the letters you have:")
word_length = st.number_input("Enter the word length (optional):", min_value=0, value=0, step=1)

if letters:
    st.header("Generated Words")
    words = generate_words(letters, length=word_length if word_length > 0 else None)
    st.write(words)

    st.header("Thesaurus Lookup")
    selected_word = st.selectbox("Select a word to look up synonyms:", [""] + sorted(words))
    if selected_word:
        synonyms = get_synonyms(selected_word)
        st.write(synonyms)