Write a piece of code in python which can solve a word search. The program should take in a 2D list (list of lists) and an array of words to find. Then it should search the word search for each word returning a dictionary of whether or not the word was found. Iterate over the 2D array and create a tree data structure of the directions proceeding from each character. Search the tree at the end for your word.
Example:
grid = [['D', 'B', 'E', 'P', 'J'],
['A', 'B', 'K', 'S', 'J'],
['F', 'B', 'O', 'T', 'J'],
['T', 'B', 'C', 'U', 'P'],
['P', 'U', 'N', 'K', 'S']]
words = ['PUN', 'PUP', 'BBU', 'JJJPS', 'COKE', 'STUK', 'PUNK', 'SPUNK', 'KNOCK']
Output:
{'PUN': True, 'PUP': False, 'BBU': True, 'JJJPS': True, 'COKE': True, 'STUK': True, 'PUNK':True, 'SPUNK': False, 'KNOCK': False}