I'm looking for one fast method to find words in Array and get them letters' indexes. Words can be put horizontally, Vertically, Diagonally, in each direction (left-right, right-left, top-bottom, bottom-top, bottomleft-topright, topright-bottomleft, bottomright-topleft, topleft-bottomright). Major problem is Diagonally dimension... How can I do?
Example:
Matrix:
[['CHYD'],
['IAOB'],
['LGTA'],
['EFGE'],
['RXBW']]
Words:
['CAT',
'DOG',
'EGO',
'RELIC',
'TOY']
I need to obtain a dictionary with keys=Rowindex and Value=[set of column indexes of found words' letters]. In my Example, I'll find:
- 'CAT' in (0,0), (1,1), (2,2)
- 'DOG' in (0,3), (1,2), (2,1)
- 'EGO' in (1,2), (2,1), (3,0)
- 'RELIC' in (0,0), (1,0), (2,0), (3,0), (4,0)
- 'TOY' in (0,2), (1,2), (2,2)
- 'TAC' in (0,0), (1,1), (2,2)
I would my final output is Found_Word={0:[0,2,3], 1:[0,1,2], 2:[0,1,2], 3:[0], 4:[0]}
Can you help me? I hope I was clear :)
P.s. I can use all Basic Python libraries (included in Anaconda Distribution), like numpy, colleciotions, itemtools and similar. I can't use Global Variables or classes.