title: Thesaurus Lab Assignment
body: <p>I have a homework assignment that I can't seem to figure out. The
  problem is:</p>
  <blockquote>
  <p>Given a set of text files containing synonyms for different words,
  complete the main program to output the synonyms for a specific word.
  Each text file contains synonyms for the word specified in the file’s
  name, and each row within the file lists the word’s synonyms that
  begin with the same letter, separated by a space. The program reads a
  word and a letter from the user and opens the text file associated
  with the input word. The program then stores the contents of the text
  file into a dictionary predefined in the program. Finally the program
  searches the dictionary and outputs all the synonyms that begin with
  the input letter, one synonym per line, or a message if no synonyms
  that begin with the input letter are found.</p>
  <p>Hints: Use the first letter of a synonym as the key when storing the
  synonym into the dictionary. Assume all letters are in lowercase.</p>
  <p>Ex: If the input of the program is:</p>
  <pre><code>educate
  c the program opens the file educate.txt, which contains:
  
  brainwash brief
  civilize coach cultivate
  develop discipline drill
  edify enlighten exercise explain
  foster
  improve indoctrinate inform instruct
  mature
  nurture
  rear
  school
  train tutor then the program outputs:
  
  civilize
  coach
  cultivate Ex: If the input of the program is:
  
  educate
  a then the program outputs:
  
  No synonyms for educate begin with a.
  </code></pre>
  </blockquote>
  <p>I currently have this with only one file being focused right now:</p>
  <pre><code>synonyms = {}   # Define dictionary
  
  initial_input = input()
  start_letter = input()
  
  
  if initial_input == 'Educate' or 'educate':
      with open('educate.txt', 'r') as e:
          lines = e.readlines()
          for word in lines:
              if ord(str(word[0])) == ord(str(start_letter)):
                  key = start_letter
                  split = word.split(' ')
                  synonyms[key] = split
                  print(synonyms)
              if ord(str(start_letter)) != ord(str(word[0])):
                  print(f'No synonyms for educate begin with {start_letter}.')
          
  elif initial_input == 'Happy' or 'happy':
      with open('happy.txt', 'r') as h:
          lines = h.readlines()
  
                  
  elif initial_input == 'Goal' or 'goal':
      with open('goal.txt', 'r') as e:
          lines = e.readlines()
  </code></pre>
  <p>and when inputting:</p>
  <pre><code>educate
  b
  </code></pre>
  <p>I get:</p>
  <pre><code>{'b': ['brainwash', 'brief\n']}
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  No synonyms for educate begin with b.
  </code></pre>
  <p>I know I can get the values individually but cannot seem to new line each entry by replacing print(synonyms) with print(word), but currently I am at a loss.</p>
  <p>Edit:
  I have modified the code a little bit and came up with:</p>
  <pre><code>if initial_input.lower() == 'educate':
      with open('educate.txt', 'r') as e:
          lines = e.readlines()
          for word in lines:
              if word[0] == start_letter:
                  split = word.split(' ')
                  synonyms[start_letter] = split
                  for x in synonyms[start_letter]:
                      print(x)
                  break
              else:
                  print(f'No synonyms for educate begin with {start_letter}.')
  </code></pre>
  <p>but see that since it reads the lines top to bottom, when changing the starting letter to 'c' for example, it outputs:</p>
  <pre><code>No synonyms for educate begin with c.
  civilize
  coach
  cultivate
  </code></pre>
  <p>How would you make it not look at the letters above?</p>