title: Python working with dictionary, files
body: <p>I have this code:</p>
  
  <pre><code>def merge_new_old_urls(urls_list, urls_file_path):
      url_dict = {}
      try:
          with open(urls_file_path, "r") as f:
              data = f.readlines()
          for line in data:
              #read what is already in file
              url_dict = { line.split()[0]: int(line.split()[1])}
          for new in urls_list:
              for key in url_dict.keys():
                  if new == key:
                      print 'found'
                      url_dict[key] += 1
                  else:
                      url_dict[new] = 1
  
      except IOError:
          logging.critical('no files to read from %s' % urls_file_path)
          raise IOError('no files to read from %s' % urls_file_path)
      return url_dict
  </code></pre>
  
  <p>This should read data from file and merge it with new list of data, counting how many times it was repeated. File with old urls looks like this:</p>
  
  <pre><code>http://aaa.com 1
  http://bbb.com 2
  http://ccc.com 1
  </code></pre>
  
  <p>if the new list of url contains <a href="http://aaa.com" rel="nofollow">http://aaa.com</a> <a href="http://bbb.com" rel="nofollow">http://bbb.com</a> the dict should be:</p>
  
  <pre><code>'http://aaa.com':2
  'http://bbb.com':3
  'http://ccc.com':1
  </code></pre>
  
  <p>But my code doesn't work right. Can someone healp ?</p>