K i (ddlmZdZdZdZdZy)) OrderedDictc|sdgSt|dts%t|dd}|Dcgc] }|df|z c}St|dd}|Dcgc]}|dD]}|f|z c}}Scc}wcc}}w)z >>> from sympy.multipledispatch.utils import expand_tuples >>> expand_tuples([1, (2, 3)]) [(1, 2), (1, 3)] >>> expand_tuples([1, 2]) [(1, 2)] rN) isinstancetuple expand_tuples)Lresttitems b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/multipledispatch/utils.pyr r s t !e $QqrU#%)*1! **QqrU#%);ad;d! ; ;;+>> from sympy.multipledispatch.utils import _toposort >>> _toposort({1: (2, 3), 2: (3, )}) [1, 2, 3] Closely follows the wikipedia page [2] [1] Kahn, Arthur B. (1962), "Topological sorting of large networks", Communications of the ACM [2] https://en.wikipedia.org/wiki/Toposort#Algorithms c3,K|] }|vs| ywNr.0vincoming_edgess r z_toposort..-sI1.1HQIs rNc3BK|]}j|dywrgetrs rrz_toposort..8s 61>  a & 6szInput has cycles) reverse_dictitemssetrfromkeyspopitemappendrremoveany ValueError) edgeskvalSr n_mrs @r _toposortr*s$"%(N0>0D0D0FGfaaSkGNIIIA A yy{1  1b! Aq)) )) 1  $ $Q '!!$!    6 66+,, HHsC#c^i}|D]%}||D]}|j|d|fz||<'|S)aReverses direction of dependence dict >>> d = {'a': (1, 2), 'b': (2, 3), 'c':()} >>> reverse_dict(d) # doctest: +SKIP {1: ('a',), 2: ('a', 'b'), 3: ('b',)} :note: dict order are not deterministic. As we iterate on the input dict, it make the output of this function depend on the dict order. So this function output order should be considered as undeterministic. rr)dresultkeyr%s rrr=sMF8S6 8C **S"-7F3K 88 Mcbi}|D]'}||}||vrg||<||j|)|S)a Group a collection by a key function >>> from sympy.multipledispatch.utils import groupby >>> 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]} See Also: ``countby`` )r)funcseqr,r r.s rgroupbyr3SsH A4j a<AcF # d  Hr/N) collectionsrr r*rr3rr/rr5s#<*! H, r/