day1/exercise/lister.py
author Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
Mon, 21 Jun 2010 03:40:59 -0400
branchscipy2010
changeset 417 caec361e3a86
parent 355 6af6441034f9
permissions -rwxr-xr-x
ENH: Added slides for FFT and basic signal processing, wherein we introduce some random number generation also. Misc. cleanup for tutorial.

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