Q:

Using `if` statement to determine if two values are in a range

I have a dictionary that looks something like this:
{'NM_100': [(0,20), (30,40), (70,90)], 'NM_200': [(0,35), (75,85), (90,100), (200,300)]}

and a tab separated file that contains this information:
isoform    strand    pos_rein1    pos_rein2
NM_100    -    32    35
NM_100    -    16    16
NM_200    -    76    77
NM_200    -    89    90

What I want to do is test if both the positions in my file fall in the same range of paired numbers in the dictionary. For example, do both 32 and 35 lie in the same range of paired numbers? (in this case they do (30,40)) If they do, proceed. If they don't (as the last case in my file), do not proceed. This is what I have so far:
import csv
with open('indel_mod0_cdsStart_rein_both.txt') as f:
    reader = csv.DictReader(f,delimiter="\t")
    for row in reader:
        pos = row['pos_rein1']
        pos2 = row['pos_rein2']
        name = row['isoform']
        strand = row['strand']
        ppos1 = int(pos)
        ppos2 = int(pos2)
        if name in exons:
            y = exons[name]
            for i, (low,high) in enumerate(exons[name]):
                if low <= ppos1 <= high: #Is there any way to edit this line to test if ppos2 is also in that range
                    exonnumber = i+1

I'm currently only testing to see if the first position falls in the range of numbers, is there an easy way to correct this to account for both of the numbers?

A:

Just use and to add a second test:
if low <= ppos1 <= high and low <= ppos2 <= high:

If you had more positions to test, you could switch to using all(), and store those positions in a sequence (here called positions):
if all(low <= pos <= high for pos in positions):

