M. A. - 8 months ago 24

Python Question

Let's say I have a list of ranges (ie.

`[[1,100][102, 200], etc]]`

`def missing(numranges):`

(minimum, maximum) = (min(map(lambda x: x[0], numranges)),

max(map(lambda x: x[1], numranges)))

(count, i) = (0, minimum)

while i < maximum:

if any(j <= i <= k for j, k in numranges):

count += 1

i += 1

return maximum - minimum - count

The problem is if you have say a number line that say is like

`[[1, 10000], [10002, 20000]]`

Edit: Sorry, should have mentioned that the number ranges could overlap (ie.

`[1, 10000], [1, 100001], [100003, 100005], etc]]`

Answer

See this code

```
l=[[1, 50], [55, 90], [95, 100]]
res=[]
for item in l :
res.extend(range(item[0],item[1]))
print [k for k in range(max(res)) if k not in res]
```

Output :

```
[0, 50, 51, 52, 53, 54, 90, 91, 92, 93, 94]
```