title: Sorting a list according to a dictionary (beginner)
body: <p>I have the following list:</p>
  
  <pre><code>listofanimals = ['Dog', 'Cat', 'Frog', 'Tiger', 'Sheep', 'Lion']
  </code></pre>
  
  <p>I would like to sort this list according to a dictionary:</p>
  
  <pre><code>score_card = {0: 'Sheep', 1: 'Dog', 2: 'Cat', 3: 'Tiger', 4: 'Frog', 5: 'Lion'}
  </code></pre>
  
  <p>Where the order of the final list has to be from 0 to 5, i.e.</p>
  
  <pre><code>numberorder = [0, 1, 2, 3, 4, 5]
  </code></pre>
  
  <p>I would like to create this inside a function. This is what I have: </p>
  
  <pre><code>def sorter():
      listofanimals = ['Dog', 'Cat', 'Frog', 'Tiger', 'Sheep', 'Lion']
      score_card = {0: 'Sheep', 1: 'Dog', 2: 'Cat', 3: 'Tiger', 4: 'Frog', 5: 'Lion'} 
      numbers = [0, 1, 2, 3, 4, 5]
      finallist = []
      for i in listofanimals:
          print(numbers[listofanimals.index(i)])
          q.append(numbers[listofanimals.index(i)])
      print(q)
      q = sorted(q)
      finallist = [score_card[j] for j in q]
      return finallist
  </code></pre>
  
  <p>I could not figure out how to convert listofanimals into numbers, so then I could sort the numbers and then feed back into the dictionary to get the values but I just cannot get it to work. Any help is appreciated. </p>