Skip to content

Commit f19b751

Browse files
authored
Merge pull request yidao620c#281 from gudongqing/patch-2
Update p08_skip_first_part_of_iterable.rst
2 parents 5401f9d + 86f97a0 commit f19b751

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

source/c04/p08_skip_first_part_of_iterable.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
4242
>>> from itertools import dropwhile
4343
>>> with open('/etc/passwd') as f:
44-
... for line in dropwhile(lambda line: line.startswith('#'), f):
44+
... for line in dropwhile(lambda line: not line.startswith('#'), f):
4545
... print(line, end='')
4646
...
4747
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
@@ -50,7 +50,7 @@
5050
>>>
5151
5252
这个例子是基于根据某个测试函数跳过开始的元素。
53-
如果你已经明确知道了要跳过的元素的个数的话,那么可以使用 ``itertools.islice()`` 来代替。比如:
53+
如果你已经明确知道了要跳过的元素的序号的话,那么可以使用 ``itertools.islice()`` 来代替。比如:
5454

5555
.. code-block:: python
5656
@@ -59,13 +59,12 @@
5959
>>> for x in islice(items, 3, None):
6060
... print(x)
6161
...
62-
1
6362
4
6463
10
6564
15
6665
>>>
6766
68-
在这个例子中, ``islice()`` 函数最后那个 ``None`` 参数指定了你要获取从第3个到最后的所有元素
67+
在这个例子中, ``islice()`` 函数最后那个 ``None`` 参数指定了你要跳过前面3个元素,获取第4个到最后的所有元素
6968
如果 ``None`` 和3的位置对调,意思就是仅仅获取前三个元素恰恰相反,
7069
(这个跟切片的相反操作 ``[3:]`` 和 ``[:3]`` 原理是一样的)。
7170

0 commit comments

Comments
 (0)