title: How to iterate over the elements of a map in python
body: <p>Given a string <code>s</code>, I want to know how many times each character at the string occurs. Here is the code:</p>
  
  <pre><code>def main() :
    while True :
      try :
        line=raw_input('Enter a string: ')
      except EOFError :
        break;
      mp={};
  
      for i in range(len(line)) :
        if line[i] in mp :
          mp[line[i]] += 1;
        else :
          mp[line[i]] = 1;
  
      for i in range(len(line)) :
        print line[i],': ',mp[line[i]];
  
  if __name__ == '__main__' :
    main();
  </code></pre>
  
  <p>When I run this code and I enter <code>abbba</code>, I get:</p>
  
  <pre><code>a : 2
  b : 3
  b : 3
  b : 3
  a : 2
  </code></pre>
  
  <p>I would like to get only:</p>
  
  <pre><code>a : 2
  b : 3
  </code></pre>
  
  <p>I understand why this is happening, but as I'm new to python, I don't know any other ways to iterate over the elements of a map. Could anyone tell me how to do this? Thanks in advance. </p>