How to select two elements from list and do math on them in Python?
<p>I have a file containing several start and end-positions of a sequence (MANY!) and I want to select the start and end positions, subtract the end position from the start to get the length of a particular sequence, and then randomly place that sequence somewhere between the smallest start number and largest end number.  Don't know if that makes any sense.....</p>

<p>However here is what I have so far:</p>

<pre><code>#!/usr/bin/env python

import sys
import random
import math
import re

file = open(sys.argv[1], 'r')

list = []

for line in file:
    if line.startswith('G'):
        continue

    else:
        pos = re.split('\s', line)
        list.append(pos[0])
        list.append(pos[1])
        list = map(int, list)
        for i in list:
            #ldom = (i:i+1)-i + 1 
print randrange(1, 3000000000, ldom)

file.close()
</code></pre>

<p>The '#' line is the one I'm having problems with. I have a list where each element represents either a start or end position, list[0] represents a start and list[1] an end position. I just don't know how to subtract list[1] from list[0], and add 1 to that number....list comprehensions only seem to work on non-specific elements or all.</p>
