title: Writing a function to print letters of a string according to their frequency compalsarily using dictionary and tuple
body: <p>I tried to define a function to <strong>print the letters of a word in decreasing order of their frequency</strong>, <em>using dictionary and tuple</em>. Two similar questions were <a href="https://stackoverflow.com/questions/991350/counting-repeated-characters-in-a-string-in-python">Counting repeated characters in a string in Python</a> and <a href="https://stackoverflow.com/questions/665942/how-to-write-a-function-that-takes-a-string-and-prints-the-letters-in-decreasing?rq=1">How to write a function that takes a string and prints the letters in decreasing order of frequency?</a>, but the difference is the sorting (by frequency) part and the algorithm.  </p>
  
  <p>Here's what I wrote :-</p>
  
  <pre><code>def most_frequent(string):
      d = dict()        #Created a dictionary
      for c in string:
          d[c] = d.get(c,0)+1  #Employed the get method to get the value of the key c
      t = d.items()     #Created a list of tuples of key-value pairs
      for letter, frequency in t:
          letter, frequency = frequency, letter  #Swapped the elements of the tuples
      t.sort(reverse = True)     #Sorting in descending order
      for frequency, letter in t:
          print (frequency," ",letter)
  </code></pre>
  
  <p>The error message produced when I call the function with "bookshopkeeper" as the argument is :-</p>
  
  <pre><code>    Traceback (most recent call last):
        File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt;
          most_frequent("bookshopkeeper")
        File "&lt;pyshell#1&gt;", line 8, in most_frequent
          t.sort(reverse = True)
      AttributeError: 'dict_items' object has no attribute 'sort'
  </code></pre>
  
  <p>I used the get method to eliminate use of if conditionals. I am using python 3.3. Please <strong>fix the code</strong>. Thanks a lot.</p>