day1/exercise/lister.py
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 12 Jan 2010 19:05:09 +0530
changeset 355 6af6441034f9
permissions -rwxr-xr-x
Added some solutions to exercises written during REC Chennai workshop.

s = "1, 3-7, 12, 15, 18-21"
answer = []
single = "answer.append( %s )"
many = "answer.extend(range(%s))"
COMMA = ','
MINUS = '-'
for p in s.split(COMMA):
    if MINUS not in p:
        eval( single % (p) )
    else:
        p = p.replace( MINUS, COMMA) + '+ 1 '
        eval( many % (p) )
print answer