How to detect the error for the list of tuples
<pre><code>l1 = [[(1,1), (1,2), (1,3)]]

for e in l1:
  for i, c in enumerate(e):
     n = re.search(r'(\d,\d)', c)
     if n:
        num = [int(y) for y in c.split(',')]
        print "num is ", num

        e[i] = Sequence_element(num[0], num[1])

if sorted(l1) != l1:
    raise ValueError, 'l1 is not in sequence' 


class Sequence_element(object):

   def __init__(self, first_elem, second_elem):
       self._first_elem = first_elem
       self._second_elem = second_elem


   def first_elem(self):
       return self._first_elem

   def second_elem(self):
      return self._second_elem
</code></pre>

<p>This code is to ensure that (1,2) comes after (1,1) and (1,3) comes after (1,1) and (1,2)</p>

<p>The error which I  sorted(l1) gives [(1,3), (1,2), (1,1)]
which is wrong because this should give [(1,1), (1,2), (1,3)] that means the error should not be  raised whereas the error is raised. </p>

<p>Each element of l1 is formed by help of another class which may be the reason that this sorted function doesn't work. What is the possible solution?</p>
