title: Adding a list of objects to a dictionary
body: <p>EDIT: This issue has been resolved. I guess I'll just leave this here for any future persons who need an example.</p>
  <p>This code takes in an input file, parses through it, passes the file to a class, stores the objects in a dictionary, and then writes out the objects in the specified format. Have any questions? I would be happy to answer them!</p>
  <p>Here is my code:</p>
  <pre><code>#C:\Python27\python.exe Animals(1).py
  
  inp = open(&quot;C:\Users\curnutte\Desktop\Assignment\Python Scripts\Python example\Classes\ClassTutorialInput.txt&quot;, &quot;r&quot;)
  outp = open(&quot;C:\Users\curnutte\Desktop\Assignment\Python Scripts\Python example\Classes\ClassTutorialOutput.txt&quot;, &quot;w&quot;)
  
  aniList = []
  
  for line in inp.readlines():
      if line == '\n':
          line = &quot;nothing&quot;
      line = line.strip()                                                        #removes '\n'
      if line != '%% ================= %%':                                       #grabs all pertinent information
          aniList.append(line)                                                    #condenses lines to one line
  print(aniList)
  
  class Animals():                                                                 #creates the Animals class
      def __init__(self, species, features, diet, drinks, threats):
          self.species = species
          self.features = features
          self.diet = diet
          self.drinks = drinks
          self.threats = threats
  
  my_animals=[]
  
  counter = 0
  for item in aniList:                                                            #iterates through the input file
      counter += 1
      if counter == 1:
          species = item
          continue
      if counter == 2:
          features = item
          continue
      if counter == 3:
          diet = item
          continue
      if counter == 4:
          drinks = item
          continue
      if counter == 5:
          threats = item
          my_animals.append(Animals(species, features, diet, drinks, threats))
          counter = 0
          continue
  
  animal_dict = {}
  
  for index in my_animals:
      animal_dict[index.species] = (index)
      print (animal_dict)
      oldLook = index.features.split(&quot;,&quot;)
      newLook = index.features
      if len(oldLook) == 2:
          newLook = oldLook[0].strip() + ' and ' + oldLook[1].strip()
      if len(oldLook) &gt; 2:
          newLook = oldLook[:-1]
          newLook = &quot;,&quot;.join(newLook)
          newLook = newLook + ' and ' + oldLook[-1].strip()
      index.features = newLook
  
      oldDiet = index.diet.split(&quot;,&quot;)
      newDiet = index.diet
      if len(oldDiet) == 2:
          newDiet = oldDiet[0].strip() + ' and ' + oldDiet[1].strip()
      if len(oldDiet) &gt; 2:
          newDiet = oldDiet[:-1]
          newDiet = &quot;,&quot;.join(newDiet)
          newDiet = newDiet + ' and ' + oldDiet[-1].strip()
      index.diet = newDiet
  
      oldPred = index.threats.split(&quot;,&quot;)
      newPred = index.threats
      if len(oldPred) == 2:
         newPred = oldPred[0].strip() + ' and ' + oldPred[1].strip()
      if len(oldPred) &gt; 2:
         newPred = oldPred[:-1]
         newPred = &quot;,&quot;.join(newPred)
         newPred = newPred + ' and ' + oldPred[-1].strip()
      index.threats = newPred
      outp.write(&quot;A %s has %s, eats %s, drinks %s, and is eaten by %s.\n&quot; % (index.species, index.features, index.diet, index.drinks, index.threats))
  
  inp.close()
  outp.close()
  </code></pre>
  <p>Here is 'ClassTutorialInput.txt':</p>
  <pre><code>deer
  fur, antlers, a peaceful disposition
  grass, leaves, roots
  water
  wolves, bear, mountain lions
  %% ================= %%
  fish
  scales, a clueless lifestyle
  bugs
  water
  sharks, humans
  %% ================= %%
  lion
  fur, manes, a blood-thirst
  antelope, humans
  water
  
  %% ================= %%
  human
  hair, skin
  vegetables, meat
  water
  
  %% ================= %%
  </code></pre>