title: How to generate a word search grid that enables words using the same letter
body: <p>I'm trying to make a word-search grid with a list of given words.
  My problem is that some of the words don't appear properly.</p>
  
  <p><strong>I have updated the code, see below</strong></p>
  
  <p>I have tried to fix the previous error and now I am getting an out of range error that i cant fix, if anyone can help I would appreciate</p>
  
  <p>Note 1: I didnt include all the program functions, if required I will include them later</p>
  
  <p>The program takes in a text file like this:</p>
  
  <blockquote>
  <pre><code>9 9  
  white  
  black  
  blue  
  green  
  pink  
  yellow  
  red  
  grey  
  purple  
  </code></pre>
  </blockquote>
  
  <p>where the first 2 numbers in the file are the dimensions of the grid, and the rest is the words to place in the grid.</p>
  
  <pre><code>import random
  import string
  fi=input('Insert the entry file name(entry.txt): ')
  fo=input('Insert the exit file name(.txt): ')
  grid_size=[]
  words=[]
  matrix=[]
  
  def read_file(storage):
      file=open(storage)
  
      n=file.readline()
      lista=n.split()
      lista=list(map(int,lista))  #sets the size of the grid
      for i in lista:
          grid_size.append(i)
  
      for line in file:
          line=line.replace("\n","")
          words.append(line)
      file.close()
  
  def grid_generator(grid_size):
      n, p = grid_size
      for i in range(n):
          matriz.append([])
          for j in range(p):
              matriz[i].append(".")   
  
  def sets_word_inside(grid_size, word, grid):
        n, p = grid_size
        word = random.choice([word,word[::-1]])  
                  #horizontal,vertical,diagonal
        d = random.choice([[1,0],[0,1],[1,1]]) 
  
        xsize = n  if d[0] == 0 else n  - len(word)
        ysize = p if d[1] == 0 else p - len(word)
  
        x= random.randrange(0,xsize)
        y= random.randrange(0,ytsize)  #position
  
        for i, letter in enumerate(word):
             char = grid[y+d[1]*i][x+d[0]*i]   
             if char != " " and char != letter:
                 # If it reaches an already filled space - restart the            process.
                 # The second condition allow the words that cross with repeated words are created.
  
                 return False
             grid[y+d[1]*i][x+d[0]*i] = letter[i]
        return True
  </code></pre>
  
  <p>For now the output of the code is something like this:</p>
  
  <pre><code>9  
  white  
  black  
  blue  
  green  
  pink  
  yellow  
  red  
  grey  
  purple  
  p w b i t y l d i  
  p v w o l e e y t  
  x g a x j r i m g  
  q i c j b g j e x  
  s s k g q l g r r  
  p i n k i o u t r  
  e l p r u p g e o  
  l a b l s r p g y  
  c o r y e u f r x  
  </code></pre>