]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] Minor doc edit: Make multinomial() the first math example (gh-132697) (gh...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 18 Apr 2025 17:47:25 +0000 (19:47 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Apr 2025 17:47:25 +0000 (17:47 +0000)
Doc/library/itertools.rst

index f996a365d56b8bea76924de985bec0414051dd42..51bbca2cf0f2d4ef011a9f3d602f2cf955624d4f 100644 (file)
@@ -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: