def isValidWord(word, hand, wordList):
    """
    Returns True if word is in the wordList and is entirely
    composed of letters in the hand. Otherwise, returns False.

    Does not mutate hand or wordList.
   
    word: string
    hand: dictionary (string -> int)
    wordList: list of lowercase strings
    """
    # MY IMPLEMENTATION
    # make copy of hand, so hand is not mutated
    handcop = hand.copy()

    # return True if both are True (AND)
    # short circuit evaluation

    # first condition: valid word is in the word list
    if word in wordList:

        # second condition: word is entirely composed of letters in the hand
        # for every letter in word
        for letter in word:
            # check whether it is key in hand dictionary and its value is still bigger than 0
            if (letter in handcop) and (handcop[letter] > 0):
                # if so, change value associated with that letter in handcop dictionary by -1
                handcop[letter] = handcop[letter] - 1
            # if either key is not in hand dictionary or its value is still equal or smaller than 0, return Flase
            elif (letter not in handcop) or (handcop[letter] <= 0):
                return False
        # loop has checked that all letters of valid word are in hand, so both conditions evaluated to True
        return True

    # elif word is not in the word list, return False
    elif word not in wordList:
        return False