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

    """
    # The result from localeconv()['grouping'], and the input to this
    # function, should be a list of integers in one of the
    # following three forms:
    #
    #   (1) an empty list, or
    #   (2) nonempty list of positive integers + [0]
    #   (3) list of positive integers + [locale.CHAR_MAX], or

    from itertools import chain, repeat
    if not grouping:
        return []
    elif grouping[-1] == 0 and len(grouping) >= 2:
        return chain(grouping[:-1], repeat(grouping[-2]))
    elif grouping[-1] == _locale.CHAR_MAX:
        return grouping[:-1]
    else:
        raise ValueError('unrecognised format for grouping')
def _group_lengths ( grouping ) : # The result from localeconv()['grouping'], and the input to this # function, should be a list of integers in one of the # following three forms: # #   (1) an empty list, or #   (2) nonempty list of positive integers + [0] #   (3) list of positive integers + [locale.CHAR_MAX], or from itertools import chain , repeat if not grouping : return [ ] elif grouping [ - 1 ] == 0 and len ( grouping ) >= 2 : return chain ( grouping [ : - 1 ] , repeat ( grouping [ - 2 ] ) ) elif grouping [ - 1 ] == _locale . CHAR_MAX : return grouping [ : - 1 ] else : raise ValueError ( 'unrecognised format for grouping' )