day1/exercise/lister.py
author Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
Mon, 21 Jun 2010 03:47:30 -0400
branchscipy2010
changeset 418 94955d4900d0
parent 355 6af6441034f9
permissions -rwxr-xr-x
Merging changes from Chris.

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