Skip to content

Commit 094a2ed

Browse files
committed
p3
1 parent 94a6b85 commit 094a2ed

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

205.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,6 @@ Python 3:
341341

342342
------
343343

344-
[总目录](./index.md)   |   [上节:函数(4)](./204.md)   |   [下节:zip()补充](./236.md)
344+
[总目录](./index.md)   |   [上节:函数(5)](./237.md)   |   [下节:zip()补充](./236.md)
345345

346346
如果你认为有必要打赏我,请通过支付宝:**[email protected]**,不胜感激。

236.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ zip()的参数是可迭代对象。例如:
1919
>>> colors = ["red", "green", "blue"]
2020
>>> values = [234, 12, 89, 65]
2121
>>> for col, val in zip(colors, values):
22-
... print (col, val)
22+
... print (col, val) #Python 3: print((col, val))
2323
...
2424
('red', 234)
2525
('green', 12)
2626
('blue', 89)
2727

2828
注意观察,zip()自动进行了匹配,并且抛弃不对应的项。
2929

30-
##参数*iterables
30+
##参数`*iterables`
3131

32-
这是zip()的雕虫小技了,在前面的文档中,zip()的参数使`*iterables`,这是什么意思呢?
32+
这是`zip()`的雕虫小技。
33+
34+
文档中显示`zip()`的参数使`*iterables`,这是什么意思呢?
3335

3436
[《函数(3)》](./203.md) 中,讲述“参数收集”和“另外一种传值”方法时,遇到过类似的参数,把其中一个例子再拿出来欣赏:
3537

@@ -42,7 +44,7 @@ zip()的参数是可迭代对象。例如:
4244
>>> add(*bars)
4345
5
4446

45-
zip()也类似上面示例中构造的那个add()函数。
47+
`zip()`也类似上面示例中构造的那个`add()`函数。
4648

4749
>>> dots = [(1, 2), (3, 4), (5, 6)]
4850
>>> x, y = zip(*dots)
@@ -56,33 +58,33 @@ zip()也类似上面示例中构造的那个add()函数。
5658
>>> m = [[1, 2],
5759
[3, 4],
5860
[5, 6]]
59-
>>> zip(*m)
61+
>>> zip(*m) #Python 3: list(zip(*m))
6062
[(1, 3, 5),
6163
(2, 4, 6)]
6264

6365
下面再看一个有点绚丽的:
6466

6567
>>> seq = range(1, 10)
66-
>>> zip(*[iter(seq)]*3)
68+
>>> zip(*[iter(seq)]*3) #Python 3: list(zip(*[iter(seq)]*3))
6769
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
6870

6971
感觉有点太炫酷了,不是太好理解。其实,分解一下,就是:
7072

7173
>>> x = iter(range(1, 10))
72-
>>> zip(x, x, x)
74+
>>> zip(x, x, x) # Python 3: list(zip(x, x, x) )
7375
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
7476

75-
这种炫酷的代码,我不提倡应用到编程实践中,这里仅仅使展示一下zip()的使用罢了。
77+
这种炫酷的代码,我不提倡应用到编程实践中,这里仅仅是展示一下`zip()`的使用罢了。
7678

77-
关于在字典中使用zip()就不做过多介绍了,因为在 [《语句(4)》](./124.md) 中已经做了完整阐述。
79+
关于在字典中使用`zip()`就不做过多介绍了,因为在 [《语句(4)》](./124.md) 中已经做了完整阐述。
7880

7981
##更酷的示例
8082

8183
最后,展示一个来自网络的示例,或许在某些时候用一下,能够人前炫耀。
8284

8385
>>> a = [1, 2, 3, 4, 5]
8486
>>> b = [2, 2, 9, 0, 9]
85-
>>> map(lambda pair: max(pair), zip(a, b))
87+
>>> map(lambda pair: max(pair), zip(a, b)) #Python 3: list(map(lambda pair: max(pair), zip(a, b)))
8688
[2, 2, 9, 4, 9]
8789

8890
参考:

0 commit comments

Comments
 (0)