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

Function parse_range

gen_videos_proj_withseg.py:202–216  ·  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

200#----------------------------------------------------------------------------
201
202def parse_range(s: Union[str, List[int]]) -> List[int]:
203 '''Parse a comma separated list of numbers or ranges and return a list of ints.
204
205 Example: '1,2,5-10' returns [1, 2, 5, 6, 7]
206 '''
207 if isinstance(s, list): return s
208 ranges = []
209 range_re = re.compile(r'^(\d+)-(\d+)$')
210 for p in s.split(','):
211 m = range_re.match(p)
212 if m:
213 ranges.extend(range(int(m.group(1)), int(m.group(2))+1))
214 else:
215 ranges.append(int(p))
216 return ranges
217
218#----------------------------------------------------------------------------
219

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected