day1/exercise/lister.py
author Nishanth Amuluru <nishanth@fossee.in>
Tue, 14 Dec 2010 23:12:25 +0530
branchscipyin2010
changeset 455 84b7a3f4a15a
parent 355 6af6441034f9
permissions -rwxr-xr-x
updated the checklist to suit new circulate

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