Skip to content

fix : reset WORDS_BY_LENGTH dictionary before building in Reverse-Hangman main #1877

Description

@tmdeveloper007

Summary of What Needs to be Done

Fix games/Reverse-Hangman-Game/Reverse-Hangman-Game.py. The WORDS_BY_LENGTH dictionary is a module-level global (defined on line 8) that gets populated inside the main() function. If main() is called multiple times (e.g., via module import or recursive calls), the dictionary accumulates duplicate word entries across calls because it is never cleared before repopulating. This causes the game to contain duplicate word entries in WORDS_BY_LENGTH, potentially leading to incorrect AI behavior.

Changes that Need to be Made

Move WORDS_BY_LENGTH = {} inside the main() function so it resets on each call, preventing accumulation of duplicate entries.

Impact that it would Provide

The AI in Reverse-Hangman will always have correct word sets regardless of how many times main() is invoked, preventing duplicate word entries from causing unpredictable AI behavior.

Note: please assign this issue to the tmdeveloper007 account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions