From 9927d302e21a0cfd18c692e2a7c331a818386a65 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 18 Apr 2025 12:41:13 -0500 Subject: [PATCH] Minor doc edit: Make multinomial() the first math example (gh-132697) (cherry picked from commit 741c6386b8615fbfb4f2e6027556751039119950) Co-authored-by: Raymond Hettinger --- Doc/library/itertools.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index f996a365d56b8b..51bbca2cf0f2d4 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -1009,6 +1009,12 @@ The following recipes have a more mathematical flavor: .. testcode:: + def multinomial(*counts): + "Number of distinct arrangements of a multiset." + # Counter('abracadabra').values() → 5 2 2 1 1 + # multinomial(5, 2, 2, 1, 1) → 83160 + return prod(map(comb, accumulate(counts), counts)) + def powerset(iterable): "Subsequences of the iterable from shortest to longest." # powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) @@ -1127,12 +1133,6 @@ The following recipes have a more mathematical flavor: n -= n // prime return n - def multinomial(*counts): - "Number of distinct arrangements of a multiset." - # Counter('abracadabra').values() → 5 2 2 1 1 - # multinomial(5, 2, 2, 1, 1) → 83160 - return prod(map(comb, accumulate(counts), counts)) - .. doctest:: :hide: