title: Debug Code: Sorting Royal names
body: <p>I got the following question in an exam and it failed some test cases which I don't have access to. The question is about sorting royal names with roman numerals. Given was a list of strings that we had to sort. The input obeyed the following constraints:</p>
  
  <p>1) length of the list <code>1 &lt;=n&lt;= 50</code></p>
  
  <p>2)Each name started with a capital letter followed by a space followed by a roman numeral between 1 and 50 inclusive.</p>
  
  <p>3) Each number is a Roman numeral with capital letters <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>#! /usr/bin/env python
  def decode(s):
      if s == "I":
          return 1
      elif s == "V":
          return 5
      elif s == "X":
          return 10
      elif s == "L":
          return 50
  
  def romanToInt(num):
      res = 0
  
      for i in range(0, len(num)-1):
          if decode(num[i]) &lt; decode(num[i+1]):
              res -= decode(num[i])
          else:
              res + decode(num[i])
  
      res = res + decode(num[len(num) - 1])
      return res
  
  
  def getSortedList(names):
  
      if len(names) == 0:
          return []
  
      copy_names = [[a,a] for a in names]
      copy_names = sorted(copy_names, key=lambda x:x[0])
      for i in range(0, len(copy_names)):
          n2 = copy_names[i][0].split(" ")
          num = str(romanToInt(n2[1]))
          copy_names[i][0] = n2[0]+ " " + num
  
  
      copy_names = sorted(copy_names, key=lambda x:x[0])
      res = [a[1] for a in copy_names]
  
      return res
  
  
  arr = ["Richard V","Henry VI","Edward II","Richard XXV","Henry IX","Edward L"]
  print getSortedList(arr)
  </code></pre>
  
  <p>I have debugged this code with multiple inputs and can't figure out what the problem is. Can anyone please point out any mistake that I am overlooking? </p>