Skip to main content

A simple (and small) library to randomly pick hangman words from a predefined wordlist.

Project description

Screenshot of code PyPI - Version

A simple Python library with a wordlist for use with hangman featuring easy, medium and hard words!

Usage

First install the package:

$ pip install the-hangman-wordlist

or

$ pip3 install the-hangman-wordlist

Then you could use it like the following example code which generates words endlessly:

from the_hangman_wordlist import HangmanWordlist

if __name__ == "__main__":
    wordlist = HangmanWordlist()

    difficulty = ""
    while difficulty not in {"easy", "medium", "hard", "random"}:
        difficulty = input("What difficulty do you want? (easy/medium/hard/random): ").lower()
        difficulty = {
            "e": "easy",
            "m": "medium",
            "h": "hard",
            "r": "random"
        }.get(difficulty, difficulty)

    script_version, wordlist_version = wordlist.version()
    print(f"Script v{script_version} and wordlist v{wordlist_version}.")

    while True:
        print(f"\n{difficulty.capitalize()} difficulty word: '{wordlist.pull_word(difficulty)}'\n")
        if input("Press Enter to generate a word or type 'exit' to quit... ").lower() == "exit":
            break

Functions

def __init__():
    # Loads when HangmanWordlist is imported, sets the variables and loads the wordlist with the load_wordlist() function.

def fetch_online_wordlist():
    # Fetches the wordlist online and returns it as json.

def load_wordlist():
    # Checks if the user has a copy of the wordlist.json and if it's up to date and then downloads it if necessary with the save_wordlist() function.

def save_wordlist(wordlist):
    # Saves the passed wordlist to wordlist.json

def pull_word(difficulty):
    # Checks if the difficulty passed is a correct option if not it chooses a random difficulty and then it returns a random word from the chosen difficulty.

def version():
    # Simply returns the current script version and wordlist version as a list like this:
    # ('script_version', 'wordlist_version')

Only the pull_word() and version() functions were made to be called by the user the different functions should be called automatically when the script is initialized.

Credits

  • Jurriaaaantje (Wordlist words and update wordlist functionality)
  • TheBiemGamer (Version check, json functionality and library)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

the_hangman_wordlist-1.0.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

the_hangman_wordlist-1.0.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file the_hangman_wordlist-1.0.3.tar.gz.

File metadata

  • Download URL: the_hangman_wordlist-1.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for the_hangman_wordlist-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1b6d6cb7de5b0f07685f1d4952c775f3572c5940159dfb57f1e07ac0d73854b5
MD5 4eee80e0e253ab13fcfda819f0caab63
BLAKE2b-256 099bcace9f6ccae61773eec90787e7a8e7daa067d2836b009015321b1c4587e7

See more details on using hashes here.

File details

Details for the file the_hangman_wordlist-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for the_hangman_wordlist-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e5385caba1b9860690190f4dc3d3f4b1fbfcaa622be2b088f3bea09376d26e4
MD5 c51e1129944b7e4306cf193620170618
BLAKE2b-256 5adb9ff0152138a8a8784feebdf5514527a697e623554d025b213351b24d18de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page