MCPcopy
hub / github.com/SizheAn/PanoHead / parse_range

Function parse_range

gen_samples.py:28–42  ·  view source on GitHub ↗

Parse a comma separated list of numbers or ranges and return a list of ints. Example: '1,2,5-10' returns [1, 2, 5, 6, 7]

(s: Union[str, List])

Source from the content-addressed store, hash-verified

26#----------------------------------------------------------------------------
27
28def parse_range(s: Union[str, List]) -> List[int]:
29 '''Parse a comma separated list of numbers or ranges and return a list of ints.
30
31 Example: '1,2,5-10' returns [1, 2, 5, 6, 7]
32 '''
33 if isinstance(s, list): return s
34 ranges = []
35 range_re = re.compile(r'^(\d+)-(\d+)$')
36 for p in s.split(','):
37 m = range_re.match(p)
38 if m:
39 ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
40 else:
41 ranges.append(int(p))
42 return ranges
43
44#----------------------------------------------------------------------------
45

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected