@@ -755,7 +755,7 @@ which incur interpreter overhead.
755755 "Count how many times the predicate is true"
756756 return sum(map(pred, iterable))
757757
758- def padnone (iterable):
758+ def pad_none (iterable):
759759 """Returns the sequence elements and then returns None indefinitely.
760760
761761 Useful for emulating the behavior of the built-in map() function.
@@ -809,7 +809,7 @@ which incur interpreter overhead.
809809 nexts = cycle(islice(nexts, num_active))
810810
811811 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"
813813 # partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9
814814 t1, t2 = tee(iterable)
815815 return filterfalse(pred, t1), filter(pred, t2)
@@ -881,7 +881,7 @@ which incur interpreter overhead.
881881 def random_product(*args, repeat=1):
882882 "Random selection from itertools.product(*args, **kwds)"
883883 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) )
885885
886886 def random_permutation(iterable, r=None):
887887 "Random selection from itertools.permutations(iterable, r)"
@@ -900,11 +900,11 @@ which incur interpreter overhead.
900900 "Random selection from itertools.combinations_with_replacement(iterable, r)"
901901 pool = tuple(iterable)
902902 n = len(pool)
903- indices = sorted(random.randrange(n) for i in range( r))
903+ indices = sorted(random.choices(range(n), k= r))
904904 return tuple(pool[i] for i in indices)
905905
906906 def nth_combination(iterable, r, index):
907- ' Equivalent to list(combinations(iterable, r))[index]'
907+ " Equivalent to list(combinations(iterable, r))[index]"
908908 pool = tuple(iterable)
909909 n = len(pool)
910910 if r < 0 or r > n:
0 commit comments