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

Function parse_range

gen_videos.py:232–246  ·  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[int]])

Source from the content-addressed store, hash-verified

230#----------------------------------------------------------------------------
231
232def parse_range(s: Union[str, List[int]]) -> List[int]:
233 '''Parse a comma separated list of numbers or ranges and return a list of ints.
234
235 Example: '1,2,5-10' returns [1, 2, 5, 6, 7]
236 '''
237 if isinstance(s, list): return s
238 ranges = []
239 range_re = re.compile(r'^(\d+)-(\d+)$')
240 for p in s.split(','):
241 m = range_re.match(p)
242 if m:
243 ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
244 else:
245 ranges.append(int(p))
246 return ranges
247
248#----------------------------------------------------------------------------
249

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected