title: How to find words in a matrix - Python
body: <p>I've made a function to search horizontally for a word in a matrix full of letters. Now I'm trying to reuse this code in order to find any word in matrix. I need to read the matrix line by line, compare the words made with my list of words (like a dictionary) and if the word exists in the list, a word has been found. 
  This is my initial code:</p>
  
  <pre><code>def search(p):  
      x=matrix() #matrix of letters
      for line in x:
          if p in ''.join(line):
              return True
  </code></pre>
  
  <p>I've written some other code but none of it works. I've been looking for similar questions but none of them answer my question. </p>
  
  <p>This is the code I have and doesn't work:</p>
  
  <pre><code>def auto_search():
      l=[] #list of words found
      x=matrix()
      for line in x:
          for i in ''.join(line):
              if search_dic(i)!=-1: #searchs in the list of words if the word is there
                  l.append(i)
      print (l)
  </code></pre>
  
  <p>For example, a have this matrix:</p>
  
  <pre><code>[[a,p,e,n],
   [g,h,j,k],
   [e,r,l,d]]
  </code></pre>
  
  <p>The function has to read the matrix and find the word "pen" by itself.
  Any help would be appreciated. Thank you</p>