<commit_before>class Solution:
    # @param start, a string
    # @param end, a string
    # @param dict, a set of string
    # @return an integer
    def ladderLength(self, start, end, dict):
        queue = []
        depth = 0
        queue.append((start, depth))
        n = len(dict)
        res = n
        while queue:
            start, depth = queue.pop()
            depth += 1
            if self.is_adjacent(start, end):
                if depth < res:
                    res = depth
            for word in set(dict):
                if self.is_adjacent(start, word):
                    queue.append((word, depth))
                    dict.remove(word)
        if res < n:
            return res + 1
        else:
            return 0

    def is_adjacent(self, word1, word2):
        count = 0
        n = len(word1)
        for i in range(n):
            if word1[i] != word2[i]:
                count += 1
        return count <= 1


s = Solution()
print s.ladderLength("hit", "cog", ["hot", "dot", "dog", "lot", "log"])
<commit_msg>Fixed bug<commit_after>class Solution:
    # @param start, a string
    # @param end, a string
    # @param dict, a set of string
    # @return an integer
    def ladderLength(self, start, end, dict):
        queue = []
        queue.append(start)
        prev = {}
        prev[start] = None
        # Remove words that are same as start
        for word in set(dict):
            if start == word:
                dict.remove(start)
        dict.add(end)
        while queue:
            cur = queue.pop(0)
            for word in set(dict):  # Iterate over the copy of dict
                if self.is_adjacent(cur, word):
                    dict.remove(word)  # Mark as visited
                    prev[word] = cur
                    queue.append(word)
        if end not in prev:
            return 0
        res = 1
        cur = end
        while prev[cur] != start:
            cur = prev[cur]
            res += 1
        return res + 1

    def is_adjacent(self, word1, word2):
        count = 0
        n = len(word1)
        for i in range(n):
            if word1[i] != word2[i]:
                count += 1
        return count == 1


s = Solution()
print s.ladderLength("hit", "dow", set(["hot", "dot", "dog", "lot", "log"]))

{'fraction_non_alphanumeric': 0.11343804537521815, 'fraction_numerical': 0.010907504363001745, 'mean_word_length': 1.4035639412997905, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866004', 'n_tokens_mistral': 693, 'n_tokens_neox': 662, 'n_words': 218}