Skip to content

Commit f2bb20e

Browse files
miss-islingtonsir-sigurd
authored andcommitted
Make code examples in Functional Programming HOWTO to be PEP 8 compliant. (pythonGH-8646)
(cherry picked from commit db8707c) Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
1 parent 6fc46a3 commit f2bb20e

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Doc/howto/functional.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ for it.
198198

199199
You can experiment with the iteration interface manually:
200200

201-
>>> L = [1,2,3]
201+
>>> L = [1, 2, 3]
202202
>>> it = iter(L)
203203
>>> it #doctest: +ELLIPSIS
204204
<...iterator object at ...>
@@ -229,7 +229,7 @@ iterator. These two statements are equivalent::
229229
Iterators can be materialized as lists or tuples by using the :func:`list` or
230230
:func:`tuple` constructor functions:
231231

232-
>>> L = [1,2,3]
232+
>>> L = [1, 2, 3]
233233
>>> iterator = iter(L)
234234
>>> t = tuple(iterator)
235235
>>> t
@@ -238,10 +238,10 @@ Iterators can be materialized as lists or tuples by using the :func:`list` or
238238
Sequence unpacking also supports iterators: if you know an iterator will return
239239
N elements, you can unpack them into an N-tuple:
240240

241-
>>> L = [1,2,3]
241+
>>> L = [1, 2, 3]
242242
>>> iterator = iter(L)
243-
>>> a,b,c = iterator
244-
>>> a,b,c
243+
>>> a, b, c = iterator
244+
>>> a, b, c
245245
(1, 2, 3)
246246

247247
Built-in functions such as :func:`max` and :func:`min` can take a single
@@ -410,7 +410,7 @@ lengths of all the sequences. If you have two lists of length 3, the output
410410
list is 9 elements long:
411411

412412
>>> seq1 = 'abc'
413-
>>> seq2 = (1,2,3)
413+
>>> seq2 = (1, 2, 3)
414414
>>> [(x, y) for x in seq1 for y in seq2] #doctest: +NORMALIZE_WHITESPACE
415415
[('a', 1), ('a', 2), ('a', 3),
416416
('b', 1), ('b', 2), ('b', 3),
@@ -478,7 +478,7 @@ Here's a sample usage of the ``generate_ints()`` generator:
478478
File "stdin", line 2, in generate_ints
479479
StopIteration
480480

481-
You could equally write ``for i in generate_ints(5)``, or ``a,b,c =
481+
You could equally write ``for i in generate_ints(5)``, or ``a, b, c =
482482
generate_ints(3)``.
483483

484484
Inside a generator function, ``return value`` causes ``StopIteration(value)``
@@ -694,17 +694,17 @@ truth values of an iterable's contents. :func:`any` returns ``True`` if any ele
694694
in the iterable is a true value, and :func:`all` returns ``True`` if all of the
695695
elements are true values:
696696

697-
>>> any([0,1,0])
697+
>>> any([0, 1, 0])
698698
True
699-
>>> any([0,0,0])
699+
>>> any([0, 0, 0])
700700
False
701-
>>> any([1,1,1])
701+
>>> any([1, 1, 1])
702702
True
703-
>>> all([0,1,0])
703+
>>> all([0, 1, 0])
704704
False
705-
>>> all([0,0,0])
705+
>>> all([0, 0, 0])
706706
False
707-
>>> all([1,1,1])
707+
>>> all([1, 1, 1])
708708
True
709709

710710

@@ -763,7 +763,7 @@ which defaults to 0, and the interval between numbers, which defaults to 1::
763763
a provided iterable and returns a new iterator that returns its elements from
764764
first to last. The new iterator will repeat these elements infinitely. ::
765765

766-
itertools.cycle([1,2,3,4,5]) =>
766+
itertools.cycle([1, 2, 3, 4, 5]) =>
767767
1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
768768

769769
:func:`itertools.repeat(elem, [n]) <itertools.repeat>` returns the provided
@@ -874,7 +874,7 @@ iterable's results. ::
874874
iterators and returns only those elements of *data* for which the corresponding
875875
element of *selectors* is true, stopping whenever either one is exhausted::
876876

877-
itertools.compress([1,2,3,4,5], [True, True, False, False, True]) =>
877+
itertools.compress([1, 2, 3, 4, 5], [True, True, False, False, True]) =>
878878
1, 2, 5
879879

880880

@@ -1034,7 +1034,7 @@ first calculation. ::
10341034
Traceback (most recent call last):
10351035
...
10361036
TypeError: reduce() of empty sequence with no initial value
1037-
>>> functools.reduce(operator.mul, [1,2,3], 1)
1037+
>>> functools.reduce(operator.mul, [1, 2, 3], 1)
10381038
6
10391039
>>> functools.reduce(operator.mul, [], 1)
10401040
1
@@ -1044,9 +1044,9 @@ elements of the iterable. This case is so common that there's a special
10441044
built-in called :func:`sum` to compute it:
10451045

10461046
>>> import functools, operator
1047-
>>> functools.reduce(operator.add, [1,2,3,4], 0)
1047+
>>> functools.reduce(operator.add, [1, 2, 3, 4], 0)
10481048
10
1049-
>>> sum([1,2,3,4])
1049+
>>> sum([1, 2, 3, 4])
10501050
10
10511051
>>> sum([])
10521052
0
@@ -1056,22 +1056,22 @@ write the obvious :keyword:`for` loop::
10561056

10571057
import functools
10581058
# Instead of:
1059-
product = functools.reduce(operator.mul, [1,2,3], 1)
1059+
product = functools.reduce(operator.mul, [1, 2, 3], 1)
10601060

10611061
# You can write:
10621062
product = 1
1063-
for i in [1,2,3]:
1063+
for i in [1, 2, 3]:
10641064
product *= i
10651065

10661066
A related function is :func:`itertools.accumulate(iterable, func=operator.add)
10671067
<itertools.accumulate>`. It performs the same calculation, but instead of
10681068
returning only the final result, :func:`accumulate` returns an iterator that
10691069
also yields each partial result::
10701070

1071-
itertools.accumulate([1,2,3,4,5]) =>
1071+
itertools.accumulate([1, 2, 3, 4, 5]) =>
10721072
1, 3, 6, 10, 15
10731073

1074-
itertools.accumulate([1,2,3,4,5], operator.mul) =>
1074+
itertools.accumulate([1, 2, 3, 4, 5], operator.mul) =>
10751075
1, 2, 6, 24, 120
10761076

10771077

@@ -1155,7 +1155,7 @@ But it would be best of all if I had simply used a ``for`` loop::
11551155

11561156
Or the :func:`sum` built-in and a generator expression::
11571157

1158-
total = sum(b for a,b in items)
1158+
total = sum(b for a, b in items)
11591159

11601160
Many uses of :func:`functools.reduce` are clearer when written as ``for`` loops.
11611161

0 commit comments

Comments
 (0)