
    E#ik                        S SK r S SKrS SKrS SKrS SKJr  S SK JrJr  S SKJ	r	  SSK
Jr  SrS r\4S	 jrS
 rS rS rS rS rS1S jrS rS rS rS rS rS rS rS rS rS r\" \S5      rS r \4S jr!S r"S r#S r$S r%S  r&S! r'\4S" jr(S# r)S$ r*S%r+\+4S& jr,S' r-S( r.\4S) jr/S* r0\\4S+ jr1S, r2S1S- jr3S. r4S/ r5S1S0 jr6g)2    N)partial)filterfalsezip_longest)Sequence   )
no_default)$remove
accumulategroupbymerge_sorted
interleaveunique
isiterable
isdistincttakedroptake_nthfirstsecondnthlastgetconcatconcatvmapcatcons	interposefrequenciesreducebyiteratesliding_window	partitionpartition_allcountpluckjointaildifftopkpeekpeeknrandom_samplec                     [        X5      $ )zReturn those items of sequence for which predicate(item) is False

>>> def iseven(x):
...     return x % 2 == 0
>>> list(remove(iseven, [1, 2, 3, 4]))
[1, 3]
)r   )	predicateseqs     b/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/toolz/itertoolz.pyr	   r	      s     y&&    c              #      #    [        U5      nU[        :X  a   [        U5      nOUnUv   U H  nU " X45      nUv   M     g! [         a     gf = f7f)a  Repeatedly apply binary function to a sequence, accumulating results

>>> from operator import add, mul
>>> list(accumulate(add, [1, 2, 3, 4, 5]))
[1, 3, 6, 10, 15]
>>> list(accumulate(mul, [1, 2, 3, 4, 5]))
[1, 2, 6, 24, 120]

Accumulate is similar to ``reduce`` and is good for making functions like
cumulative sum:

>>> from functools import partial, reduce
>>> sum    = partial(reduce, add)
>>> cumsum = partial(accumulate, add)

Accumulate also takes an optional argument that will be used as the first
value. This is similar to reduce.

>>> list(accumulate(add, [1, 2, 3], -1))
[-1, 0, 2, 5]
>>> list(accumulate(add, [], 1))
[1]

See Also:
    itertools.accumulate :  In standard itertools for Python 3.2+
N)iterr   nextStopIteration)binopr/   initialresultelems        r0   r
   r
      s^     6 s)C*	#YF 
Lv$   		s'   AA A
AAAAc                     [        U 5      (       d  [        U 5      n [        R                  " S 5      nU H  nX " U5         " U5        M     0 nUR	                  5        H  u  pVUR
                  XE'   M     U$ )a  Group a collection by a key function

>>> names = ['Alice', 'Bob', 'Charlie', 'Dan', 'Edith', 'Frank']
>>> groupby(len, names)  # doctest: +SKIP
{3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}

>>> iseven = lambda x: x % 2 == 0
>>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8])  # doctest: +SKIP
{False: [1, 3, 5, 7], True: [2, 4, 6, 8]}

Non-callable keys imply grouping on a member.

>>> groupby('gender', [{'name': 'Alice', 'gender': 'F'},
...                    {'name': 'Bob', 'gender': 'M'},
...                    {'name': 'Charlie', 'gender': 'M'}]) # doctest:+SKIP
{'F': [{'gender': 'F', 'name': 'Alice'}],
 'M': [{'gender': 'M', 'name': 'Bob'},
       {'gender': 'M', 'name': 'Charlie'}]}

Not to be confused with ``itertools.groupby``

See Also:
    countby
c                      / R                   $ N)append r1   r0   <lambda>groupby.<locals>.<lambda>b   s    		r1   )callablegettercollectionsdefaultdictitems__self__)keyr/   ditemrvkvs          r0   r   r   G   sh    2 C==Sk 12A	#d)T 	B	

 Ir1   c                      [        U 5      S:X  a  [        / 5      $ [        U 5      S:X  a  [        U S   5      $ UR                  SS5      nUc  [        U 5      $ [	        X5      $ )a  Merge and sort a collection of sorted collections

This works lazily and only keeps one value from each iterable in memory.

>>> list(merge_sorted([1, 3, 5], [2, 4, 6]))
[1, 2, 3, 4, 5, 6]

>>> ''.join(merge_sorted('abc', 'abc', 'abc'))
'aaabbbccc'

The "key" function used to sort the input may be passed as a keyword.

>>> list(merge_sorted([2, 3], [1, 3], key=lambda x: x // 3))
[2, 1, 3, 3]
r   r   rG   N)lenr3   r   _merge_sorted_binary_merge_sorted_binary_key)seqskwargsrG   s      r0   r   r   k   s\      4yA~Bx	TaDG}
**UD
!C
{#D))'22r1   c              #     #    [        U 5      S-  nU S U n[        U5      S:X  a  [        US   5      nO[        U5      nXS  n[        U5      S:X  a  [        US   5      nO[        U5      n [        U5      nU H+  nXg:  a  Uv   U H  nXg:  a  Uv   M  Uv     M#       OUv   M-     Uv   U H  nUv   M	     g Uv   U H  nUv   M	     g ! [         a    U H  nUv   M	      g f = f7fN   r   r   )rN   r3   rO   r4   r5   )rQ   midL1seq1L2seq2val2val1s           r0   rO   rO      s    
d)q.C	dsB
2w!|BqE{#B'	dB
2w!|BqE{#B'Dz ;J;JJ  J  
DJ 
J
 1  DJ s+   A*C*-C 8AC*C'$C*&C''C*c              #     #    [        U 5      S-  nU S U n[        U5      S:X  a  [        US   5      nO[        X15      nXS  n[        U5      S:X  a  [        US   5      nO[        XQ5      n [        U5      nU" U5      n	U H;  nU" U5      n
X:  a'  Uv   U H  nU" U5      n	X:  a  Uv   M  Uv     M3       OUv   M=     Uv   U H  nUv   M	     g Uv   U H  nUv   M	     g ! [         a    U H  nUv   M	      g f = f7frT   )rN   r3   rP   r4   r5   )rQ   rG   rV   rW   rX   rY   rZ   r[   r\   key2key1s              r0   rP   rP      s    
d)q.C	dsB
2w!|BqE{'0	dB
2w!|BqE{'0Dz
 t9D4y;J4y;JJ  J   
DJ 
J
 7  DJ s+   A*D-C% 8A-D%C?<D>C??Dc              #   0  #    [         R                  " [        [        U 5      5      n  U H  n[	        U5      v   M     g! [
         aG    [        [        R                  W5      n[         R                  " [         R                  " X15      5      n Of = fMn  7f)zInterleave a sequence of sequences

>>> list(interleave([[1, 2], [3, 4]]))
[1, 3, 2, 4]

>>> ''.join(interleave(('ABC', 'XY')))
'AXBYC'

Both the individual sequences and the sequence of sequences may be infinite

Returns a lazy iterator
N)
	itertoolscyclemapr3   r4   r5   r   operatoris_not	takewhile)rQ   itersitrr.   s       r0   r   r      sy      OOCdO,E
	K3i  	K5IOOI$7$7	$IJE	K s(   &BA  B ABBBBc              #      #    [        5       nUR                  nUc  U  H  nXB;  d  M
  U" U5        Uv   M     gU  H  nU" U5      nXR;  d  M  U" U5        Uv   M      g7f)zReturn only unique elements of a sequence

>>> tuple(unique((1, 2, 3)))
(1, 2, 3)
>>> tuple(unique((1, 2, 1, 3)))
(1, 2, 3)

Uniqueness can be defined by key keyword

>>> tuple(unique(['cat', 'mouse', 'dog', 'hen'], key=len))
('cat', 'mouse')
N)setadd)r/   rG   seenseen_addrI   vals         r0   r   r      s^      5DxxH
{D
 
 Dd)C
	 s   "A!AAc                 <     [        U 5        g! [         a     gf = f)zbIs x iterable?

>>> isiterable([1, 2, 3])
True
>>> isiterable('abc')
True
>>> isiterable(5)
False
TF)r3   	TypeErrorxs    r0   r   r     s#    Q s    
c                     [        U 5      U L a/  [        5       nUR                  nU  H  nX1;   a    gU" U5        M     g[        U 5      [        [        U 5      5      :H  $ )zAll values in sequence are distinct

>>> isdistinct([1, 2, 3])
True
>>> isdistinct([1, 2, 1])
False

>>> isdistinct("Hello")
False
>>> isdistinct("World")
True
FT)r3   rj   rk   rN   )r/   rl   rm   rI   s       r0   r   r   %  sU     CyCu88D|TN  3x3s3x=((r1   c                 .    [         R                  " X5      $ )zrThe first n elements of a sequence

>>> list(take(2, [10, 20, 30, 40, 50]))
[10, 20]

See Also:
    drop
    tail
ra   islicenr/   s     r0   r   r   >  s     C##r1   c                 x     X* S $ ! [         [        4 a"    [        [        R                  " X5      5      s $ f = f)zkThe last n elements of a sequence

>>> tail(2, [10, 20, 30, 40, 50])
[40, 50]

See Also:
    drop
    take
N)rp   KeyErrortuplerC   dequerw   s     r0   r'   r'   K  s<    023xx  0[&&s.//0s    /99c                 0    [         R                  " XS5      $ )zThe sequence following the first n elements

>>> list(drop(2, [10, 20, 30, 40, 50]))
[30, 40, 50]

See Also:
    take
    tail
Nru   rw   s     r0   r   r   [  s     CD))r1   c                 4    [         R                  " USSU 5      $ )zPEvery nth item in seq

>>> list(take_nth(2, [10, 20, 30, 40, 50]))
[10, 30, 50]
r   Nru   rw   s     r0   r   r   h  s     CD!,,r1   c                 *    [        [        U 5      5      $ )z6The first element in a sequence

>>> first('ABC')
'A'
)r4   r3   r/   s    r0   r   r   q  s     S	?r1   c                 D    [        U 5      n [        U 5        [        U 5      $ )z8The second element in a sequence

>>> second('ABC')
'B'
)r3   r4   r   s    r0   r   r   z  s     s)CI9r1   c                     [        U[        [        [        45      (       a  X   $ [	        [
        R                  " XS5      5      $ )z5The nth element in a sequence

>>> nth(1, 'ABC')
'B'
N)
isinstancer{   listr   r4   ra   rv   rw   s     r0   r   r     s7     #tX.//vI$$ST233r1   c                      [        SU 5      S   $ )z4The last element in a sequence

>>> last('ABC')
'C'
r   r   )r'   r   s    r0   r   r     s     3<?r1   c                 <     X   $ ! [         [        4 a    Us $ f = fr<   )rz   
IndexErrorindr/   defaults      r0   _getr     s'    xj! s    c                 r  ^^  TU    $ ! [          a    [        U [        5      (       a`  T[        :X  a>  [	        U 5      S:  a  [
        R                  " U 6 " T5      s $ U (       a  TU S      4s $  g[        UU4S jU  5       5      s $ T[        :w  a  Ts $ e [        [        4 a    T[        :X  a  e Ts $ f = f)a  Get element in a sequence or dict

Provides standard indexing

>>> get(1, 'ABC')       # Same as 'ABC'[1]
'B'

Pass a list to get multiple values

>>> get([1, 2], 'ABC')  # ('ABC'[1], 'ABC'[2])
('B', 'C')

Works on any value that supports indexing/getitem
For example here we see that it works with dictionaries

>>> phonebook = {'Alice':  '555-1234',
...              'Bob':    '555-5678',
...              'Charlie':'555-9999'}
>>> get('Alice', phonebook)
'555-1234'

>>> get(['Alice', 'Bob'], phonebook)
('555-1234', '555-5678')

Provide a default for missing values

>>> get(['Alice', 'Dennis'], phonebook, None)
('555-1234', None)

See Also:
    pluck
r   r   r>   c              3   >   >#    U  H  n[        UTT5      v   M     g 7fr<   r   ).0ir   r/   s     r0   	<genexpr>get.<locals>.<genexpr>  s     @CqT!S'22C   )
rp   r   r   r   rN   rd   
itemgetterr{   rz   r   r   s    ``r0   r   r     s    B3x c4  *$s8a<#..4S99s1v;<'@C@@@
"Nj! j N	s(   	 AB6B60B6B6B65B6c                 @    [         R                  R                  U 5      $ )aV  Concatenate zero or more iterables, any of which may be infinite.

An infinite sequence will prevent the rest of the arguments from
being included.

We use chain.from_iterable rather than ``chain(*seqs)`` so that seqs
can be a generator.

>>> list(concat([[], [1], [2, 3]]))
[1, 2, 3]

See also:
    itertools.chain.from_iterable  equivalent
)ra   chainfrom_iterablerQ   s    r0   r   r     s     ??((..r1   c                      [        U 5      $ )ztVariadic version of concat

>>> list(concatv([], ["a"], ["b", "c"]))
['a', 'b', 'c']

See also:
    itertools.chain
)r   r   s    r0   r   r     s     $<r1   c                 *    [        [        X5      5      $ )zApply func to each sequence in seqs, concatenating results.

>>> list(mapcat(lambda s: [c.upper() for c in s],
...             [["a", "b"], ["c", "d", "e"]]))
['A', 'B', 'C', 'D', 'E']
)r   rc   )funcrQ   s     r0   r   r     s     #d/""r1   c                 2    [         R                  " U /U5      $ )z^Add el to beginning of (possibly infinite) sequence seq.

>>> list(cons(1, [2, 3]))
[1, 2, 3]
)ra   r   )elr/   s     r0   r   r     s     ??B4%%r1   c                 n    [        [        [        R                  " U 5      U5      5      n[	        U5        U$ )zpIntroduce element between each pair of elements in seq

>>> list(interpose("a", [1, 2, 3]))
[1, 'a', 2, 'a', 3]
)r   zipra   repeatr4   )r   r/   inposeds      r0   r   r     s,     S))"-s34GMNr1   c                 v    [         R                  " [        5      nU  H  nX==   S-  ss'   M     [        U5      $ )zFind number of occurrences of each value in seq

>>> frequencies(['cat', 'cat', 'ox', 'pig', 'pig', 'cat'])  #doctest: +SKIP
{'cat': 3, 'ox': 1, 'pig': 2}

See Also:
    countby
    groupby
r   )rC   rD   intdict)r/   rH   rI   s      r0   r   r     s2     	$A	1 7Nr1   c                   ^ U[         :H  nU(       d  [        U5      (       d  UmU4S jn[        U 5      (       d  [        U 5      n 0 nU H3  nU " U5      nXu;  a  U(       a  XeU'   M  U" 5       XW'   U" XW   U5      XW'   M5     U$ )a  Perform a simultaneous groupby and reduction

The computation:

>>> result = reduceby(key, binop, seq, init)      # doctest: +SKIP

is equivalent to the following:

>>> def reduction(group):                           # doctest: +SKIP
...     return reduce(binop, group, init)           # doctest: +SKIP

>>> groups = groupby(key, seq)                    # doctest: +SKIP
>>> result = valmap(reduction, groups)              # doctest: +SKIP

But the former does not build the intermediate groups, allowing it to
operate in much less space.  This makes it suitable for larger datasets
that do not fit comfortably in memory

The ``init`` keyword argument is the default initialization of the
reduction.  This can be either a constant value like ``0`` or a callable
like ``lambda : 0`` as might be used in ``defaultdict``.

Simple Examples
---------------

>>> from operator import add, mul
>>> iseven = lambda x: x % 2 == 0

>>> data = [1, 2, 3, 4, 5]

>>> reduceby(iseven, add, data)  # doctest: +SKIP
{False: 9, True: 6}

>>> reduceby(iseven, mul, data)  # doctest: +SKIP
{False: 15, True: 8}

Complex Example
---------------

>>> projects = [{'name': 'build roads', 'state': 'CA', 'cost': 1000000},
...             {'name': 'fight crime', 'state': 'IL', 'cost': 100000},
...             {'name': 'help farmers', 'state': 'IL', 'cost': 2000000},
...             {'name': 'help farmers', 'state': 'CA', 'cost': 200000}]

>>> reduceby('state',                        # doctest: +SKIP
...          lambda acc, x: acc + x['cost'],
...          projects, 0)
{'CA': 1200000, 'IL': 2100000}

Example Using ``init``
----------------------

>>> def set_add(s, i):
...     s.add(i)
...     return s

>>> reduceby(iseven, set_add, [1, 2, 3, 4, 1, 2, 3], set)  # doctest: +SKIP
{True:  set([2, 4]),
 False: set([1, 3])}
c                     > T $ r<   r>   )_inits   r0   r?   reduceby.<locals>.<lambda>i  s    ur1   )r   rA   rB   )	rG   r6   r/   initis_no_defaultrH   rI   rK   r   s	           @r0   r   r   )  s    z J&M$C==Sk
AI:!vQT4   Hr1   c              #   (   #     Uv   U " U5      nM  7f)a  Repeatedly apply a function func onto an original input

Yields x, then func(x), then func(func(x)), then func(func(func(x))), etc..

>>> def inc(x):  return x + 1
>>> counter = iterate(inc, 0)
>>> next(counter)
0
>>> next(counter)
1
>>> next(counter)
2

>>> double = lambda x: x * 2
>>> powers_of_two = iterate(double, 1)
>>> next(powers_of_two)
1
>>> next(powers_of_two)
2
>>> next(powers_of_two)
4
>>> next(powers_of_two)
8
r>   )r   rr   s     r0   r    r    y  s     2 G s   c           	      Z    [        S [        [        R                  " X5      5       5       6 $ )aG  A sequence of overlapping subsequences

>>> list(sliding_window(2, [1, 2, 3, 4]))
[(1, 2), (2, 3), (3, 4)]

This function creates a sliding window suitable for transformations like
sliding means / smoothing

>>> mean = lambda seq: float(sum(seq)) / len(seq)
>>> list(map(mean, sliding_window(2, [1, 2, 3, 4])))
[1.5, 2.5, 3.5]
c              3      #    U  H;  u  p[         R                  " [        R                  " X!5      S 5      =(       d    Uv   M=     g7f)r   N)rC   r|   ra   rv   )r   r   its      r0   r   !sliding_window.<locals>.<genexpr>  s9      ><51 ""9#3#3B#:A>D"D<s   AA)r   	enumeratera   teerw   s     r0   r!   r!     s,      >%immC&;<> ? ?r1   __no__pad__c                 X    [        U5      /U -  nU[        L a  [        U6 $ [        USU06$ )a  Partition sequence into tuples of length n

>>> list(partition(2, [1, 2, 3, 4]))
[(1, 2), (3, 4)]

If the length of ``seq`` is not evenly divisible by ``n``, the final tuple
is dropped if ``pad`` is not specified, or filled to length ``n`` by pad:

>>> list(partition(2, [1, 2, 3, 4, 5]))
[(1, 2), (3, 4)]

>>> list(partition(2, [1, 2, 3, 4, 5], pad=None))
[(1, 2), (3, 4), (5, None)]

See Also:
    partition_all
	fillvalue)r3   no_padr   r   )rx   r/   padargss       r0   r"   r"     s4    $ I;?D
f}DzD0C00r1   c              #   h  #    [        U5      /U -  n[        US[        06n [        U5      nU H	  nUv   UnM     US   [        L a   US[        U5      U -   v   gUv   g! [         a     gf = f! [         a3    SU pvXg:  a!  Xg-   S-  nXH   [        L a  UnOUS-   nXg:  a  M!  USU v    gf = f7f)a  Partition all elements of sequence into tuples of length at most n

The final tuple may be shorter to accommodate extra elements.

>>> list(partition_all(2, [1, 2, 3, 4]))
[(1, 2), (3, 4)]

>>> list(partition_all(2, [1, 2, 3, 4, 5]))
[(1, 2), (3, 4), (5,)]

See Also:
    partition
r   Nr   rU   r   )r3   r   r   r4   r5   rN   rp   )	rx   r/   r   r   prevrI   lohirV   s	            r0   r#   r#     s      I;?D	d	-f	-BBx 
  Bx6	 }C1%% 
1    	
 'w1n9&BqB ' s)O	sQ   B2A" B2	A2 B2"
A/,B2.A//B221B/%B/,B2.B//B2c                 ^    [        U S5      (       a  [        U 5      $ [        S U  5       5      $ )zCount the number of items in seq

Like the builtin ``len`` but works on lazy sequences.

Not to be confused with ``itertools.count``

See also:
    len
__len__c              3   &   #    U  H  nS v   M	     g7f)r   Nr>   )r   r   s     r0   r   count.<locals>.<genexpr>  s     #Qq#s   )hasattrrN   sumr   s    r0   r$   r$     s+     sI3x#r1   c                    ^ ^ T[         :X  a  [        T 5      n[        X15      $ [        T [        5      (       a  UU 4S jU 5       $ UU 4S jU 5       $ )aP  plucks an element or several elements from each item in a sequence.

``pluck`` maps ``itertoolz.get`` over a sequence and returns one or more
elements of each item in the sequence.

This is equivalent to running `map(curried.get(ind), seqs)`

``ind`` can be either a single string/index or a list of strings/indices.
``seqs`` should be sequence containing sequences or dicts.

e.g.

>>> data = [{'id': 1, 'name': 'Cheese'}, {'id': 2, 'name': 'Pies'}]
>>> list(pluck('name', data))
['Cheese', 'Pies']
>>> list(pluck([0, 1], [[1, 2, 3], [4, 5, 7]]))
[(1, 2), (4, 5)]

See Also:
    get
    map
c              3   R   >^#    U  H  m[        UU4S  jT 5       5      v   M     g7f)c              3   >   >#    U  H  n[        UTT5      v   M     g 7fr<   r   )r   rI   r   r/   s     r0   r   "pluck.<locals>.<genexpr>.<genexpr>  s     ?34d4g..3r   N)r{   r   r/   r   r   s    @r0   r   pluck.<locals>.<genexpr>  s&      !C ?3???s   #'c              3   >   >#    U  H  n[        TUT5      v   M     g 7fr<   r   r   s     r0   r   r     s     4tDc7##tr   )r   rB   rc   r   r   )r   rQ   r   r   s   ` ` r0   r%   r%      sJ    . *Sk3~	C		!! 	!4t44r1   c                    ^  [        T [        5      (       a7  [        T 5      S:X  a  T S   m U 4S j$ T (       a  [        R                  " T 6 $ S $ [        R                  " T 5      $ )Nr   r   c                    > U T   4$ r<   r>   )rr   indexs    r0   r?   getter.<locals>.<lambda>$  s    ah[r1   c                     g)Nr>   r>   rq   s    r0   r?   r   (  s    Rr1   )r   r   rN   rd   r   )r   s   `r0   rB   rB      sU    %u:?!HE((&&..""5))r1   c              #   
  #    [        U 5      (       d  [        U 5      n [        U5      (       d  [        U5      n[        X5      nU[        :X  a3  U[        :X  a)  U H"  nU" U5      nX;   d  M  Xh    H  n	X4v   M
     M$     gU[        :w  a8  U[        :X  a.  U H'  nU" U5      nX;   a  Xh    H  n	X4v   M
     M"  XG4v   M)     gU[        :w  a  [	        5       n
U
R
                  nU[        :X  a1  U H*  nU" U5      nU" U5        X;   d  M  Xh    H  n	X4v   M
     M,     O5U H/  nU" U5      nU" U5        X;   a  Xh    H  n	X4v   M
     M*  XG4v   M1     UR                  5        H  u  pX;  d  M  U H  nX4v   M
     M     gg7f)a|  Join two sequences on common attributes

This is a semi-streaming operation.  The LEFT sequence is fully evaluated
and placed into memory.  The RIGHT sequence is evaluated lazily and so can
be arbitrarily large.
(Note: If right_default is defined, then unique keys of rightseq
    will also be stored in memory.)

>>> friends = [('Alice', 'Edith'),
...            ('Alice', 'Zhao'),
...            ('Edith', 'Alice'),
...            ('Zhao', 'Alice'),
...            ('Zhao', 'Edith')]

>>> cities = [('Alice', 'NYC'),
...           ('Alice', 'Chicago'),
...           ('Dan', 'Sydney'),
...           ('Edith', 'Paris'),
...           ('Edith', 'Berlin'),
...           ('Zhao', 'Shanghai')]

>>> # Vacation opportunities
>>> # In what cities do people have friends?
>>> result = join(second, friends,
...               first, cities)
>>> for ((a, b), (c, d)) in sorted(unique(result)):
...     print((a, d))
('Alice', 'Berlin')
('Alice', 'Paris')
('Alice', 'Shanghai')
('Edith', 'Chicago')
('Edith', 'NYC')
('Zhao', 'Chicago')
('Zhao', 'NYC')
('Zhao', 'Berlin')
('Zhao', 'Paris')

Specify outer joins with keyword arguments ``left_default`` and/or
``right_default``.  Here is a full outer join in which unmatched elements
are paired with None.

>>> identity = lambda x: x
>>> list(join(identity, [1, 2, 3],
...           identity, [2, 3, 4],
...           left_default=None, right_default=None))
[(2, 2), (3, 3), (None, 4), (1, None)]

Usually the key arguments are callables to be applied to the sequences.  If
the keys are not obviously callable then it is assumed that indexing was
intended, e.g. the following is a legal change.
The join is implemented as a hash join and the keys of leftseq must be
hashable. Additionally, if right_default is defined, then keys of rightseq
must also be hashable.

>>> # result = join(second, friends, first, cities)
>>> result = join(1, friends, 0, cities)  # doctest: +SKIP
N)rA   rB   r   r   rj   rk   rE   )leftkeyleftseqrightkeyrightseqleft_defaultright_defaultrH   rI   rG   
left_match	seen_keysrl   matchesmatchs                 r0   r&   r&   -  s    v G/H(#!Az!mz&AD4.Cx"#&J%,, #) 
 
	#(CD4.Cx"#&J%,, #) $**  
*	$E	}}:% tnS	8&'f
)00 '-	 ! !tnS	8&'f
)00 '- (.. ! GGILC#$E 00 % &/ 
%s   A&F,BF	A"F/Fc               /     #    [        U 5      nUS:X  a(  [        U S   [        5      (       a  U S   n [        U 5      nUS:  a  [        S5      eUR	                  S[
        5      nU[
        :X  a	  [        U 6 nO[        U SU06nUR	                  SS5      nUc(  U H!  nUR                  US   5      U:w  d  M  Uv   M#     gU H5  n[        [        XV5      5      nUR                  US   5      U:w  d  M1  Uv   M7     g7f)	a  Return those items that differ between sequences

>>> list(diff([1, 2, 3], [1, 2, 10, 100]))
[(3, 10)]

Shorter sequences may be padded with a ``default`` value:

>>> list(diff([1, 2, 3], [1, 2, 10, 100], default=None))
[(3, 10), (None, 100)]

A ``key`` function may also be applied to each item to use during
comparisons:

>>> list(diff(['apples', 'bananas'], ['Apples', 'Oranges'], key=str.lower))
[('bananas', 'Oranges')]
r   r   rU   z(Too few sequences given (min 2 required)r   r   rG   N)rN   r   r   rp   r   r   r   r   r$   r{   rc   )rQ   rR   Nr   rg   rG   rE   valss           r0   r(   r(     s     " 	D	AAv*T!Wd++AwI1uBCCjjJ/G*T
T5W5
**UD
!C
{E{{58$)  ES)Dzz$q'"a' s   B/C:58C:1	C:c                 z    Ub  [        U5      (       d  [        U5      n[        [        R                  " XUS95      $ )a  Find the k largest elements of a sequence

Operates lazily in ``n*log(k)`` time

>>> topk(2, [1, 100, 10, 1000])
(1000, 100)

Use a key function to change sorted order

>>> topk(2, ['Alice', 'Bob', 'Charlie', 'Dan'], key=len)
('Charlie', 'Alice')

See also:
    heapq.nlargest
)rG   )rA   rB   r{   heapqnlargest)rK   r/   rG   s      r0   r)   r)     s0      x}}SkC011r1   c                 b    [        U 5      n[        U5      nU[        R                  " U4U5      4$ )zRetrieve the next element of a sequence

Returns the first element and an iterable equivalent to the original
sequence, still having the element retrieved.

>>> seq = [0, 1, 2, 3, 4]
>>> first, seq = peek(seq)
>>> first
0
>>> list(seq)
[0, 1, 2, 3, 4]
)r3   r4   ra   r   )r/   iteratorrI   s      r0   r*   r*     s.     CyH>D$(333r1   c                     [        U5      n[        [        X5      5      nU[        R                  " [        U5      U5      4$ )a  Retrieve the next n elements of a sequence

Returns a tuple of the first n elements and an iterable equivalent
to the original, still having the elements retrieved.

>>> seq = [0, 1, 2, 3, 4]
>>> first_two, seq = peekn(2, seq)
>>> first_two
(0, 1)
>>> list(seq)
[0, 1, 2, 3, 4]
)r3   r{   r   ra   r   )rx   r/   r   peekeds       r0   r+   r+     s6     CyH4$%F9??4<:::r1   c                 f   ^ ^ [        TS5      (       d  SSKJn  U" T5      m[        U U4S jU5      $ )aW  Return elements from a sequence with probability of prob

Returns a lazy iterator of random items from seq.

``random_sample`` considers each item independently and without
replacement. See below how the first time it returned 13 items and the
next time it returned 6 items.

>>> seq = list(range(100))
>>> list(random_sample(0.1, seq)) # doctest: +SKIP
[6, 9, 19, 35, 45, 50, 58, 62, 68, 72, 78, 86, 95]
>>> list(random_sample(0.1, seq)) # doctest: +SKIP
[6, 44, 54, 61, 69, 94]

Providing an integer seed for ``random_state`` will result in
deterministic sampling. Given the same seed it will return the same sample
every time.

>>> list(random_sample(0.1, seq, random_state=2016))
[7, 9, 19, 25, 30, 32, 34, 48, 59, 60, 81, 98]
>>> list(random_sample(0.1, seq, random_state=2016))
[7, 9, 19, 25, 30, 32, 34, 48, 59, 60, 81, 98]

``random_state`` can also be any object with a method ``random`` that
returns floats between 0.0 and 1.0 (exclusive).

>>> from random import Random
>>> randobj = Random(2016)
>>> list(random_sample(0.1, seq, random_state=randobj))
[7, 9, 19, 25, 30, 32, 34, 48, 59, 60, 81, 98]
randomr   )Randomc                 *   > TR                  5       T:  $ r<   )r   )_probrandom_states    r0   r?   random_sample.<locals>.<lambda>!  s    L//1D8r1   )r   r   r   filter)r   r/   r   r   s   ` ` r0   r,   r,     s.    @ <**!l+8#>>r1   r<   )7ra   r   rC   rd   	functoolsr   r   r   collections.abcr   utilsr   __all__r	   r
   r   r   rO   rP   r   r   r   r   r   r'   r   r   r   r   r   r   restr   r   r   r   r   r   r   r   r   r    r!   r   r"   r#   r$   r%   rB   r&   r(   r)   r*   r+   r,   r>   r1   r0   <module>r      s/        . $ M' $. &R!H38(V+\K08")2
$0 
*-	4 tQ % 6r/$	#&  $. M`<?" 
 ! 12*Z ( 5@
* !
l1^%P2*4$;$$?r1   