Write a function to solve a specific algorithm problem using Python.
Implement ladder_length to return the number of words in the shortest transformation from begin_word to end_word. Change exactly one character at a time, and every intermediate word must belong to word_list. Return 0 if no transformation exists. The function must handle duplicate words and avoid revisiting states efficiently.
Input: two lowercase words of equal length and a list of lowercase words.
Output: an integer path length, including both endpoints.
def ladder_length(begin_word, end_word, word_list):