comparing and replacing the elements of a nested list
<p>I have got a list which is:</p>

<pre><code>mylist = {
           'a': [(-1,-1), (0.2,0.4)] 
           'b': [(0.3,1.0), (-1,-1)]
           'c': [(-1,-1), (-1,-1)]
           'd': [(0.15,0.35), (0.05,0.15)]
          }
</code></pre>

<p>I have to get an output which will be like the following:</p>

<pre><code> mylist = {
           'a': [(0.3, 0.35), (0.2,0.4)] 
           'b': [(0.3,0.35), (0.05,0.15)]
           'c': [(0.15,0.35), (0.05,0.15)]
           'd': [(0.15,0.35), (0.05,0.15)]
          }
</code></pre>

<p>The list above looks like this when I print it,</p>

<pre><code>mylist = [ ('a', [ (-1, -1), (0.2, 0.4) ] ), 
           ('b', [ (0.3, 1.0), (-1, -1) ] ), 
           ('c', [ (-1, -1), (-1, -1) ] ), 
           ('d', [ (0.15, 0.35), (0.05, 0.15) ] ) ]
</code></pre>

<p>Now the algorithm is like the following:</p>

<pre><code>1st iteration: Compare a[0] and b[0] ie (-1, -1) and (0.3, 1.0). 
               Here replace (-1, -1) by (0.3, 1.0). 
               Rule: (-1, -1) is considered as empty or not in use so 
                     it gets replaced while comparison. 

               Similarly, compare a[1] and b[1] ie (0.2, 0.4) and (-1, -1). 
               Here keep the same value as b[1] is empty so no change. 

               Hence the new elements of 'a' are (0.3, 1.0), (0.2, 0.4). 
               Rule: if comparing with empty one then keep the same values.

2nd iteration: Compare new values of a[0] and c[0] ie (0.3, 1.0) and (-1, -1). 
               Here again no change. 
               Similarly, compare new values of a[1] and c[1] ie (0.2, 0.4) and (-1, -1).
               Here also no change. 
               Now the new elements of 'a' are (0.3, 1.0), (0.2, 0.4).
</code></pre>

<p>This process carries till 'a' is compared to the last element in the list here its upto 'd'. Then comes the turn of 'b' and same thing will continue between 'b' and 'c' then 'b and 'd' and so on. </p>

<p>The other rules when comparison between two actual ranges (0.1,0.3) and (0.5,1.0). </p>

<p>Say if two ranges totally overlap like (0.1, 0.8) and (0.3, 0.9) then,
it should take the common between them which is (0.3, 0.8). </p>

<p>If they don't overlap like (0.1, 0.4) and (0.5, 0.9) then,
it should choose its own which is (0.1, 0.4). </p>

<p>And if they partially overlap then also take the common between them.
Like (0.4, 1.0) and (0.8, 1.5) then it should choose (0.8, 1.0).   </p>

<p>P.S. The values (0.2, 0.4) are the ranges actually indicating the actual value will vary between 0.2 to 0.4. I think now I have explained a bit more clearly. Thank you</p>
