python - find a number between a range of numbers -


i have file1 has ranges this

10 20

50 60

70 100

150 170

....

....

file2

15

55

80

160

....

....

i want read ranges in file1 , in file2 , values between them

final output:

15 value between 10 , 20

55 value between 50 , 60

....

....

if want results other print them out, can create dictionary maps ranges (from file1) numbers within ranges (from file2.)

ranges = [] open('file1') f:     line in f:         ranges.append(line.strip().split(' ')) ranges = [tuple(int(_) _ in r) r in ranges] in_range = {range_: set() range_ in ranges} open('file2') f:     line in f:         num = int(line.strip())         range_ in ranges:             if range_[0] < num < range_[1] # between low , high                 in_range.add(num) # print in_range 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -