示例#1
0
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2,s3), ..."
    split1, split2 = itertools.tee(iterable)
    a, b = itertools.tee(split1)
    test1, test2 = itertools.tee(split2)
    next(b, None)
    if next(test1, None) is None:
        ret = py23_zip(a, b)  # Returns empty list
    elif next(test2, None) is not None and next(test2, None) is None:
        ret = py23_zip(a, [None])  # Return at least one value
    else:
        ret = py23_zip(a, b)
    del test1, test2, split2
    return ret
示例#2
0
def _py3_safe(parsed_list, use_locale, check):
    """Insert '' between two numbers."""
    length = len(parsed_list)
    if length < 2:
        return parsed_list
    else:
        new_list = [parsed_list[0]]
        nl_append = new_list.append
        for before, after in py23_zip(islice(parsed_list, 0, length - 1),
                                      islice(parsed_list, 1, None)):
            if check(before, num_only=True) and check(after, num_only=True):
                nl_append(null_string if use_locale else '')
            nl_append(after)
        return new_list
示例#3
0
def _py3_safe(parsed_list, use_locale, check):
    """Insert '' between two numbers."""
    length = len(parsed_list)
    if length < 2:
        return parsed_list
    else:
        new_list = [parsed_list[0]]
        nl_append = new_list.append
        for before, after in py23_zip(islice(parsed_list, 0, length-1),
                                      islice(parsed_list, 1, None)):
            if check(before, num_only=True) and check(after, num_only=True):
                nl_append(null_string if use_locale else '')
            nl_append(after)
        return new_list