OwlCyberSecurity - MANAGER
Edit File: recipes.cpython-38.pyc
U �[p: � @ s� d Z ddlmZ ddlmZmZmZmZmZm Z m Z mZmZ ddl Z ddlmZmZmZ ddlmZ ddlmZmZmZmZmZmZ dd d ddd ddddddddddddddddddd d!d"d#gZe jfd$d�Zd%d!� ZdAd&d�Zd'd � Z dBd(d �Z!dCd)d�Z"d*d � Z#e$fd+d�Z%d,d� Z&d-d� Z'd.d� Z(d/d � Z)dDd0d�Z*d1d� Z+dEd2d�Z,d3d� Z-d4d� Z.d5d� Z/dFd6d"�Z0dGd7d#�Z1dHd8d�Z2dId:d�Z3d;d� Z4dJd<d�Z5d=d� Z6d>d� Z7d?d� Z8d@d� Z9dS )Ka Imported from the recipes section of the itertools documentation. All functions taken from the recipes section of the itertools library docs [1]_. Some backward-compatible usability improvements have been made. .. [1] http://docs.python.org/library/itertools.html#recipes � )�deque) �chain�combinations�count�cycle�groupby�islice�repeat�starmap�teeN)� randrange�sample�choice)�PY2)�filter�filterfalse�map�range�zip�zip_longest� accumulate� all_equal�consume� dotproduct� first_true�flatten�grouper�iter_except�ncycles�nth�nth_combination�padnone�pairwise� partition�powerset�prepend�quantify�#random_combination_with_replacement�random_combination�random_permutation�random_product� repeatfunc� roundrobin�tabulate�tail�take�unique_everseen�unique_justseenc c sP t | �}zt|�}W n tk r* Y dS X |V |D ]}|||�}|V q6dS )a_ Return an iterator whose items are the accumulated results of a function (specified by the optional *func* argument) that takes two arguments. By default, returns accumulated sums with :func:`operator.add`. >>> list(accumulate([1, 2, 3, 4, 5])) # Running sum [1, 3, 6, 10, 15] >>> list(accumulate([1, 2, 3], func=operator.mul)) # Running product [1, 2, 6] >>> list(accumulate([0, 1, -1, 2, 3, 2], func=max)) # Running maximum [0, 1, 1, 2, 3, 3] This function is available in the ``itertools`` module for Python 3.2 and greater. N)�iter�next� StopIteration)�iterable�func�itZtotal�element� r9 �8/usr/lib/python3/dist-packages/more_itertools/recipes.pyr 4 s c C s t t|| ��S )a. Return first *n* items of the iterable as a list. >>> take(3, range(10)) [0, 1, 2] >>> take(5, range(3)) [0, 1, 2] Effectively a short replacement for ``next`` based iterator consumption when you want more than one item, but less than the whole iterator. )�listr ��nr5 r9 r9 r: r/ R s c C s t | t|��S )a� Return an iterator over the results of ``func(start)``, ``func(start + 1)``, ``func(start + 2)``... *func* should be a function that accepts one integer argument. If *start* is not specified it defaults to 0. It will be incremented each time the iterator is advanced. >>> square = lambda x: x ** 2 >>> iterator = tabulate(square, -3) >>> take(4, iterator) [9, 4, 1, 0] )r r )Zfunction�startr9 r9 r: r- a s c C s t t|| d��S )z�Return an iterator over the last *n* items of *iterable*. >>> t = tail(3, 'ABCDEFG') >>> list(t) ['E', 'F', 'G'] ��maxlen)r2 r r<