Construct intervals from a sequence of numbers and vice versa
For the first part of making sequence to intervals, you could do this instead (prob. more Pythonic?)  (This can be converted to a function easier - leave for the exercise)
&gt;&gt;&gt; # if x-1 not in seq:  x becomes start point
&gt;&gt;&gt; # if y+1 not in seq:  y becomes end point
&gt;&gt;&gt; starts = [x for x in seq if x-1 not in seq]
&gt;&gt;&gt; ends =  [y for y in seq if y+1 not in seq]
&gt;&gt;&gt; ends
[3, 7, 9]
&gt;&gt;&gt; intervals = [str(a)+'-'+str(b) for a, b in zip(starts, ends)]
&gt;&gt;&gt; intervals
['1-3', '6-7', '9-9']
&gt;&gt;&gt; 

[Note - last interval could be 'fixed' too  - if we see start_point == end_point. Leave as an exercise.]
Then for the second part, it would be quite similar:
&gt;&gt;&gt; seq = []
&gt;&gt;&gt; for inter in intervals:
    s, e = inter.split('-')
    seq += list(range(int(s), int(e)+1))
&gt;&gt;&gt; seq
[1, 2, 3, 6, 7, 9]