The Hangman Wordlist is a Python package designed to provide a diverse selection of words for playing the classic game of Hangman. It features a robust word list that can be updated from an online source, allowing for fresh gameplay experiences. This package was created by Noah Bozkurt and Jurriaan Portier.
You can install the package via pip:
pip install the-hangman-wordlist
- Word Retrieval: Fetches a word list from an online source to ensure it is up-to-date.
- Local Caching: Saves the word list locally to minimize download time and ensure availability offline.
- Difficulty Levels: Supports three levels of difficulty: easy, medium, and hard.
- Random Word Selection: Allows for random word selection across different difficulties.
To use the Hangman Wordlist package, import it and create an instance of HangmanWordlist
:
from the_hangman_wordlist import HangmanWordlist
# Initialize the wordlist
wordlist = HangmanWordlist()
To pull a word from the list, use the pull_word method. You can specify the difficulty level or let the package choose one at random:
word = wordlist.pull_word(diff="easy") # Pulls an easy word
If you want a random word regardless of difficulty:
word = wordlist.pull_word() # Pulls a word from any difficulty
To retrieve the current package version and the word list version, use the version method:
script_version, wordlist_version = wordlist.version()
print(f"Library v{script_version} and wordlist v{wordlist_version}.")
Here is a simple script demonstrating how to use the package:
from the_hangman_wordlist import HangmanWordlist
if __name__ == "__main__":
wordlist = HangmanWordlist()
print("This is the example script for The Hangman Wordlist")
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"Library 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
For a full example hangman game with the package see example/hangman.py.
This project is licensed under the MIT License. See the LICENSE file for details.