summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-02-13 10:04:17 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-02-13 10:04:17 (GMT)
commitcfd31f0af20f76849bbec6185efea01c72349f2a (patch)
tree56d492ed757ac819d6c082bc23bc503fe3f3b799
parent73d600239b0aa34198bce2b7982e4ff14c92f119 (diff)
downloadcpython-cfd31f0af20f76849bbec6185efea01c72349f2a.zip
cpython-cfd31f0af20f76849bbec6185efea01c72349f2a.tar.gz
cpython-cfd31f0af20f76849bbec6185efea01c72349f2a.tar.bz2
Be consistent about the use of from-imports in random module (GH-11837)
Minor code clean-up.
-rw-r--r--Lib/random.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 8925b52..754b295 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -43,8 +43,8 @@ from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
from os import urandom as _urandom
from _collections_abc import Set as _Set, Sequence as _Sequence
from hashlib import sha512 as _sha512
-import itertools as _itertools
-import bisect as _bisect
+from itertools import accumulate as _accumulate
+from bisect import bisect as _bisect
import os as _os
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
@@ -390,12 +390,12 @@ class Random(_random.Random):
_int = int
n += 0.0 # convert to float for a small speed improvement
return [population[_int(random() * n)] for i in range(k)]
- cum_weights = list(_itertools.accumulate(weights))
+ cum_weights = list(_accumulate(weights))
elif weights is not None:
raise TypeError('Cannot specify both weights and cumulative weights')
if len(cum_weights) != n:
raise ValueError('The number of weights does not match the population')
- bisect = _bisect.bisect
+ bisect = _bisect
total = cum_weights[-1] + 0.0 # convert to float
hi = n - 1
return [population[bisect(cum_weights, random() * total, 0, hi)]