title: dynamically creating keys and values in a Python dictionary
body: <p>The problem I am trying to solve is reading in a file in that contains a list of words. Then counting the number of vowels in each word and display each word in a table along with the number of its vowels and the total vowels in the word, and at the end display the total number of vowels in all of the words.</p>
  
  <p>I am trying to solve the problem by reading the file in through a for loop and creating a dictionary that is associated with every word like </p>
  
  <pre><code>mississippi['a_count' : 0, 'e_ocunt' : 0, 'i_count' : 4 ,'o_count' : 0, 'u_count' : 0, 'y_count' : 0]
  </code></pre>
  
  <p>My problem is that I am not sure how to create the dictionaries as the variable changes due to a loop. I am just ending up with empty dictionaries.</p>
  
  <p>here's a screenshot of my output <a href="http://imgur.com/mksgdTc" rel="nofollow">http://imgur.com/mksgdTc</a></p>
  
  <p>my test code in the file is Mississippi California  Wisconsin all on different lines.</p>
  
  <pre><code>try:
      word_file = open("vowel.txt", "r")
  
      count = 0
      dic = {}
  
      a_count = 0
      e_count = 0
      i_count = 0
      o_count = 0
      u_count = 0
      y_count = 0
      total_count = 0
  
      #this establishes the top of the table
      print('Number','{:&gt;8}'.format('word'),'{:&gt;8}'.format('A'),'{:&gt;4}'.format('E'),'{:&gt;4}'.format('I'),'{:&gt;4}'.format('O'),'{:&gt;4}'.format('U'),'{:&gt;4}'.format('Y'),'{:&gt;8}'.format('Total'))
      print("__________________________________________________________")
  
  
      for word in word_file:
          count+=1
          word = {}
          print(word)
  
          word_a_count = 0
          word_e_count = 0
          word_i_count = 0
          word_o_count = 0
          word_u_count = 0
          word_y_count = 0
          word_total_count = 0
  
          for letters in word:
              print(letters)
              if letters.lower() == "a":
                  a_count+= 1
                  total_count += 1
                  word_a_count +=1
                  word['a_count'] = word_a_count
              if letters.lower() == "e":
                  e_count+= 1
                  total_count += 1
                  word_e_count +=1
                  word['e_count'] = word_e_count
              if letters.lower() == "i":
                  i_count+= 1
                  total_count += 1
                  word_i_count +=1
                  word['i_count'] = word_i_count
              if letters.lower() == "o":
                  o_count+= 1
                  total_count += 1
                  word_o_count +=1
                  word['o_count'] = word_o_count
              if letters.lower() == "u":
                  u_count+= 1
                  total_count += 1
                  word_u_count +=1
                  word['u_count'] = word_u_count
              if letters.lower() == "y":
                  y_count+= 1
                  total_count += 1
                  word_y_count +=1
                  word['y_count'] = word_y_count
  
              print('Totals','{:&gt;8}'.format('    '),'{:&gt;8}'.format(word['a_count']),'{:&gt;4}'.format\
              (word['e_count']),'{:&gt;4}'.format(word['i_count']),'{:&gt;4}'.format\
              (word['o_count']),'{:&gt;4}'.format(word['u_count']),'{:&gt;4}'.\
              format(word['y_count']))
  
      #this creates the bottom barrier of the table
      print("__________________________________________________________")
  
      #code for totals print
      print('Totals','{:&gt;8}'.format('    '),'{:&gt;8}'.format(a_count),'{:&gt;4}'.format(e_count),'{:&gt;4}'.format(i_count),'{:&gt;4}'.format(o_count),'{:&gt;4}'.format(u_count),'{:&gt;4}'.format(y_count),'{:&gt;6}'.format(total_count))
  
  except IOError:
      print("The file does not seem to exists. The program is halting.")
  </code></pre>