title: How do I sort a dictionary by the occurrence of the word NOT alphabetically in python
body: <p>I am new to coding and I am starting with python. I am trying to sort dictinary by the occurrence of the word. here is the code i am using</p>
  <pre><code>lis = ['Now when I am faced with a new situation I am not so nervous.'] 
  for word in lis:
  
        word = word.strip()
        word = word.lower()
        each = word.split(&quot; &quot;)
  
  for p in each:
        lis.append(p)
  
  d = {}
  
  
  for p in lis:
      if p in d:
          d[p] = d[p] + 1
      else:
          d[p] = 1
  
  for c in sorted(d):
      print(c, d[c])
  </code></pre>
  <p>here is the result, i am getting alphabetically</p>
  <pre><code>a 1
  am 2
  faced 1
  i 2
  nervous. 1
  new 1
  not 1
  now 1
  situation 1
  so 1
  when 1
  with 1
  </code></pre>
  <p>and here is the result I am trying to get. ordered or sorted by the frequency of the word.
  as you can see start with the biggest number which in this case 2.</p>
  <pre><code>i 2
  am 2
  now 1
  when 1
  faced 1
  with 1
  a 1
  new 1
  situation 1
  not 1
  so 1
  nervous 1
  </code></pre>