day1/exercise/lister.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Mon, 08 Mar 2010 20:45:33 +0530
changeset 379 682b6f66fe11
parent 355 6af6441034f9
permissions -rwxr-xr-x
Updated for day1 of GRD 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