day1/exercise/strrange.py
changeset 64 333092b68926
equal deleted inserted replaced
63:f5eac04a00fe 64:333092b68926
       
     1 str_ranges = "1, 3-7, 12, 15, 18-21"
       
     2 
       
     3 ranges = str_ranges.split(',')
       
     4 
       
     5 lst = []
       
     6 for r in ranges:
       
     7     vals = r.split('-')
       
     8     if len(vals) == 2:
       
     9        lst.extend(range(int(vals[0]), int(vals[1]) + 1))
       
    10     else:
       
    11        lst.append(int(vals[0]))
       
    12 
       
    13 print lst