day1/exercise/lister.py
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 10 Dec 2010 00:04:46 +0530
branchscipyin2010
changeset 449 49e10e9fc660
parent 355 6af6441034f9
permissions -rwxr-xr-x
Fixed day2/session1.tex.

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