Minor doc edit: Make multinomial() the first math example (gh-132697)

This commit is contained in:
Raymond Hettinger 2025-04-18 12:41:13 -05:00 committed by GitHub
parent 1d5dc5f1c3
commit 741c6386b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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: