Python itertools 模块,html() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用itertools.html()

项目:camel-snake-pep8    作者:abarker    | 项目源码 | 文件源码
def unique_everseen(iterable, key=None):
    "List unique elements, preserving order. Remember all elements ever seen."
    # unique_everseen('AAAABBBCCDAABBB') --> A B C D
    # unique_everseen('ABBCcAD', str.lower) --> A B C D
    # https://docs.python.org/3/library/itertools.html#recipes
    seen = set()
    seen_add = seen.add
    if key is None:
        for element in itertools.ifilterfalse(seen.__contains__, iterable):
            seen_add(element)
            yield element
    else:
        for element in iterable:
            k = key(element)
            if k not in seen:
                seen_add(k)
                yield element

#
# Parsing function parameter strings (to find the parameters without default values).
#
项目:Python-iBeacon-Scan    作者:NikNitro    | 项目源码 | 文件源码
def __iter__(self):
        import itertools

        # roundrobin recipe taken from itertools documentation:
        # https://docs.python.org/2/library/itertools.html#recipes
        def roundrobin(*iterables):
            "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
            # Recipe credited to George Sakkis
            pending = len(iterables)
            if PY3:
                nexts = itertools.cycle(iter(it).__next__ for it in iterables)
            else:
                nexts = itertools.cycle(iter(it).next for it in iterables)
            while pending:
                try:
                    for next in nexts:
                        yield next()
                except StopIteration:
                    pending -= 1
                    nexts = itertools.cycle(itertools.islice(nexts, pending))

        if all(set.is_iterable for set in self.args):
            return roundrobin(*(iter(arg) for arg in self.args))
        else:
            raise TypeError("Not all constituent sets are iterable")
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def grouper(n, iterable, fillvalue=None):
    # http://docs.python.org/dev/3.0/library/itertools.html#module-itertools
    "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
    args = [iter(iterable)] * n
    return itertools.zip_longest(fillvalue=fillvalue, *args)
项目:rltk    作者:usc-isi-i2    | 项目源码 | 文件源码
def __copy__(self):
        """
            Clone the iterator include states
        """
        # https://docs.python.org/2/library/itertools.html#itertools.tee
        # tee is not that helpful here, and it will also occupy a lot of memory
        # self._file_handler, new_iter = itertools.tee(self._file_handler)

        new_iter = FileIterator(self._file_path, self._type, **self._kwargs)
        if self._line_count > 0:
            for _ in new_iter:
                if new_iter._line_count == self._line_count:
                    break
        return new_iter
项目:ga4gh-common    作者:ga4gh    | 项目源码 | 文件源码
def powerset(iterable, maxSets=None):
    """
    powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)

    See https://docs.python.org/2/library/itertools.html#recipes
    """
    s = list(iterable)
    return itertools.islice(itertools.chain.from_iterable(
        itertools.combinations(s, r) for r in range(len(s) + 1)),
        0, maxSets)
项目:ww    作者:Tygs    | 项目源码 | 文件源码
def lasts(iterable, items=1, default=None):
    # type: (Iterable[T], int, T) -> Iterable[T]
    """ Lazily return the last x items from this iterable or default. """

    last_items = deque(iterable, maxlen=items)

    for _ in range(items - len(last_items)):
        yield default

    for y in last_items:
        yield y

# reduce is technically the last value of accumulate
# use ww.utils.EMPTY instead of EMPTY
# Put in the doc than scan=fold=accumulare and reduce=accumulate
# replace https://docs.python.org/3/library/itertools.html#itertools.accumulate
# that works only on Python 3.3 and doesn't have echo_start
# def accumulate(func, iterable, start=ww.utils.EMPTY, *, echo_start=True):
#     """
#     Scan higher-order function.
#     The first 3 positional arguments are alike to the ``functools.reduce``
#     signature. This function accepts an extra optional ``echo_start``
#     parameter that controls whether the first value should be in the output.
#     """
#     it = iter(iterable)
#     if start is ww.utils._EMPTY:
#         start = next(it)
#     if echo_start:
#         yield start
#     for item in it:
#         start = func(start, item)
# yield start
项目:rnn-morpheme-analyzer    作者:mitaki28    | 项目源码 | 文件源码
def progress(prompt, percent, bar_length=20):
    hashes = '#' * int(round(percent * bar_length))
    spaces = ' ' * (bar_length - len(hashes))    
    return "\r{}: [{}] {}%".format(
        prompt,
        hashes + spaces,
        int(round(percent * 100)))

#ref: https://docs.python.org/3.5/library/itertools.html#itertools.zip_longest
项目:bareon-allocator    作者:openstack    | 项目源码 | 文件源码
def grouper(iterable, n, fillvalue=None):
    """Collect data into fixed-length chunks or blocks.

    Source: https://docs.python.org/2/library/itertools.html#recipes
    """
    args = [iter(iterable)] * n
    return itertools.izip_longest(fillvalue=fillvalue, *args)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def product(*args, **kwds):
    """
    Taken from http://docs.python.org/library/itertools.html#itertools.product
    """
    # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
    # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
    pools = map(tuple, args) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)
项目:twitterresearch    作者:trifle    | 项目源码 | 文件源码
def grouper(iterable, n, fillvalue=None):
    """
    Collect data into fixed-length chunks or blocks
    Recipe from itertools documentation
    https://docs.python.org/2/library/itertools.html
    """
    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
    args = [iter(iterable)] * n
    return itertools.zip_longest(fillvalue=fillvalue, *args)