MCPcopy Index your code
hub / github.com/python/cpython / _group_lengths

Function _group_lengths

Lib/_pydecimal.py:6269–6290  ·  view source on GitHub ↗

Convert a localeconv-style grouping into a (possibly infinite) iterable of integers representing group lengths.

(grouping)

Source from the content-addressed store, hash-verified

6267 return result
6268
6269def _group_lengths(grouping):
6270 """Convert a localeconv-style grouping into a (possibly infinite)
6271 iterable of integers representing group lengths.
6272
6273 """
6274 # The result from localeconv()['grouping'], and the input to this
6275 # function, should be a list of integers in one of the
6276 # following three forms:
6277 #
6278 # (1) an empty list, or
6279 # (2) nonempty list of positive integers + [0]
6280 # (3) list of positive integers + [locale.CHAR_MAX], or
6281
6282 from itertools import chain, repeat
6283 if not grouping:
6284 return []
6285 elif grouping[-1] == 0 and len(grouping) >= 2:
6286 return chain(grouping[:-1], repeat(grouping[-2]))
6287 elif grouping[-1] == _locale.CHAR_MAX:
6288 return grouping[:-1]
6289 else:
6290 raise ValueError('unrecognised format for grouping')
6291
6292def _insert_thousands_sep(digits, spec, min_width=1):
6293 """Insert thousands separators into a digit string.

Callers 1

_insert_thousands_sepFunction · 0.85

Calls 2

chainFunction · 0.85
repeatFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…