@@ -755,7 +755,7 @@ which incur interpreter overhead.
755
755
"Count how many times the predicate is true"
756
756
return sum(map(pred, iterable))
757
757
758
- def padnone (iterable):
758
+ def pad_none (iterable):
759
759
"""Returns the sequence elements and then returns None indefinitely.
760
760
761
761
Useful for emulating the behavior of the built-in map() function.
@@ -809,7 +809,7 @@ which incur interpreter overhead.
809
809
nexts = cycle(islice(nexts, num_active))
810
810
811
811
def partition(pred, iterable):
812
- ' Use a predicate to partition entries into false entries and true entries'
812
+ " Use a predicate to partition entries into false entries and true entries"
813
813
# partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9
814
814
t1, t2 = tee(iterable)
815
815
return filterfalse(pred, t1), filter(pred, t2)
@@ -881,7 +881,7 @@ which incur interpreter overhead.
881
881
def random_product(*args, repeat=1):
882
882
"Random selection from itertools.product(*args, **kwds)"
883
883
pools = [tuple(pool) for pool in args] * repeat
884
- return tuple(random.choice(pool) for pool in pools)
884
+ return tuple(map( random.choice, pools) )
885
885
886
886
def random_permutation(iterable, r=None):
887
887
"Random selection from itertools.permutations(iterable, r)"
@@ -900,11 +900,11 @@ which incur interpreter overhead.
900
900
"Random selection from itertools.combinations_with_replacement(iterable, r)"
901
901
pool = tuple(iterable)
902
902
n = len(pool)
903
- indices = sorted(random.randrange(n) for i in range( r))
903
+ indices = sorted(random.choices(range(n), k= r))
904
904
return tuple(pool[i] for i in indices)
905
905
906
906
def nth_combination(iterable, r, index):
907
- ' Equivalent to list(combinations(iterable, r))[index]'
907
+ " Equivalent to list(combinations(iterable, r))[index]"
908
908
pool = tuple(iterable)
909
909
n = len(pool)
910
910
if r < 0 or r > n:
0 commit comments