title: Crossword Solving Companion
body: <p>I am writing a program that takes letters and indexes and spits out crossword answers (not a crossword solver, but a tool to aid in solving crosswords, if that makes sense).</p>
  
  <p>I've written two versions of the algorithm, but neither seems to work correctly. The first one I tried was this:</p>
  
  <pre><code>fin = open('words.txt')
  
  def answer_finder():
      global fin
      possible_answers = []
      length = int(raw_input("How long is the word?"))
      letter_1 = raw_input("What is the first letter that you know?").lower
      letter_1_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_2 = raw_input("What is the second letter that you know?").lower
      letter_2_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_3 = raw_input("What is the third letter that you know?").lower
      letter_3_index = int(raw_input("How many letters into the word is that letter?")) - 1
      for i in fin:
          if len(i) == length:
              if i[letter_1_index] == letter_1 and i[letter_2_index] == letter_2 and i[letter_3_index] == letter_3:
                  possible_answers.append(i)
      return possible_answers
  </code></pre>
  
  <p>I realize it's kinda ugly, but this was more of a proof of concept for the algorithm. The user input will be changed later. Anyway, this seems to return an empty list no matter what I try.</p>
  
  <p>The second version was essentially the same, but relied on nested if statements instead of boolean operators:</p>
  
  <pre><code>def answer_finder():
      global fin
      possible_answers = []
      length = int(raw_input("How long is the word?"))
      letter_1 = raw_input("What is the first letter that you know?").lower
      letter_1_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_2 = raw_input("What is the second letter that you know?").lower
      letter_2_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_3 = raw_input("What is the third letter that you know?").lower
      letter_3_index = int(raw_input("How many letters into the word is that letter?")) - 1
      for i in fin:
          if len(i) == length:
              if i[letter_1_index] == letter_1:
                  if i[letter_2_index] == letter_2:
                      if i[letter_3_index] == letter_3:
                          possible_answers.append(i)
      return possible_answers
  </code></pre>
  
  <p>This, too, returns an empty list. The list of words I am using comes from <a href="http://thinkpython.com/code/words.txt" rel="nofollow">here</a>. I'm assuming I am missing something obvious, since I'm new to working with external files. I should point out that these functions are prototypes of the former, and both work just fine:</p>
  
  <pre><code>def greater_than_20():
      global fin
      li = []
      for i in fin:
          if len(i) &gt; 20:
              li.append(i)
      return li
  
  def first_letter_length_finder():
      global fin
      length = int(raw_input("How long is the word?"))
      first_letter = raw_input("What is the first letter?")
      li = []
      for i in fin:
          if len(i) == length and i[0] == first_letter:
              li.append(i)
      print li
      return li
  </code></pre>
  
  <p>EDIT: Just for reference, here is the code in its entirety (including commented-out sections of code.)</p>
  
  <pre><code>fin = open('words.txt')
  print fin
  
  def greater_than_20():
      global fin
      li = []
      for i in fin:
          if len(i) &gt; 20:
              li.append(i)
      return li
  
  def first_letter_length_finder():
      global fin
      length = int(raw_input("How long is the word?"))
      first_letter = raw_input("What is the first letter?")
      li = []
      for i in fin:
          if len(i) == length and i[0] == first_letter:
              li.append(i)
      print li
      return li
  
  def answer_finder():
      global fin
      possible_answers = []
      length = int(raw_input("How long is the word?"))
      letter_1 = raw_input("What is the first letter that you know?").lower
      letter_1_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_2 = raw_input("What is the second letter that you know?").lower
      letter_2_index = int(raw_input("How many letters into the word is that letter?")) - 1
      letter_3 = raw_input("What is the third letter that you know?").lower
      letter_3_index = int(raw_input("How many letters into the word is that letter?")) - 1
      for i in fin:
          if len(i) == length:
  #            if i[letter_1_index] == letter_1 and i[letter_2_index] == letter_2 and i[letter_3_index] == letter_3:
  #                possible_answers.append(i)
              if i[letter_1_index] == letter_1:
                  if i[letter_2_index] == letter_2:
                      if i[letter_3_index] == letter_3:
                          possible_answers.append(i)
      return possible_answers
  </code></pre>