Skip to content

Commit cfd31f0

Browse files
rhettingermiss-islington
authored andcommitted
Be consistent about the use of from-imports in random module (GH-11837)
Minor code clean-up.
1 parent 73d6002 commit cfd31f0

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/random.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
from os import urandom as _urandom
4444
from _collections_abc import Set as _Set, Sequence as _Sequence
4545
from hashlib import sha512 as _sha512
46-
import itertools as _itertools
47-
import bisect as _bisect
46+
from itertools import accumulate as _accumulate
47+
from bisect import bisect as _bisect
4848
import os as _os
4949

5050
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
@@ -390,12 +390,12 @@ def choices(self, population, weights=None, *, cum_weights=None, k=1):
390390
_int = int
391391
n += 0.0 # convert to float for a small speed improvement
392392
return [population[_int(random() * n)] for i in range(k)]
393-
cum_weights = list(_itertools.accumulate(weights))
393+
cum_weights = list(_accumulate(weights))
394394
elif weights is not None:
395395
raise TypeError('Cannot specify both weights and cumulative weights')
396396
if len(cum_weights) != n:
397397
raise ValueError('The number of weights does not match the population')
398-
bisect = _bisect.bisect
398+
bisect = _bisect
399399
total = cum_weights[-1] + 0.0 # convert to float
400400
hi = n - 1
401401
return [population[bisect(cum_weights, random() * total, 0, hi)]

0 commit comments

Comments
 (0)