title: python3 opening files and reading lines
body: <p>Can you explain what is going on in this code? I don't seem to understand
  how you can open the file and read it line by line instead of all of the sentences at the same time in a for loop. Thanks</p>
  
  <p>Let's say I have these sentences in a document file:</p>
  
  <pre><code>cat:dog:mice
  cat1:dog1:mice1
  cat2:dog2:mice2
  cat3:dog3:mice3
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>from sys import argv
  
  filename = input("Please enter the name of a file: ")
  f = open(filename,'r')
  
  d1ct = dict()
  print("Number of times each animal visited each station:")
  print("Animal Id           Station 1           Station 2")
  
  for line in f:
       if '\n' == line[-1]:
            line = line[:-1]
       (AnimalId, Timestamp, StationId,) = line.split(':')
       key = (AnimalId,StationId,)
       if key not in d1ct:
            d1ct[key] = 0
       d1ct[key] += 1
  </code></pre>