迭代
<span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; line-height: 20px; white-space: nowrap; background-color: rgb(250, 250, 250);">for key in d.key()</span>
<span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; line-height: 20px; white-space: nowrap; background-color: rgb(250, 250, 250);">for value in d.values()</span>
<span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; line-height: 20px; white-space: nowrap; background-color: rgb(250, 250, 250);">for k, v in d.items()</span>
<span style="color: rgb(102, 102, 102); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px; white-space: pre-wrap;">list变成索引-元素对</span>
enumerate
列表生成
<span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; line-height: 20px; white-space: nowrap; background-color: rgb(250, 250, 250);">list(range(1, 11))</span>
[x * x for x in range(1, 11)]
[m + n for m in 'ABC' for n in 'XYZ']
<font color="#666666" face="Helvetica Neue, Helvetica, Arial, sans-serif"><span style="font-size: 14px; line-height: 20px; white-space: pre-wrap;">[s.lower() for s in L]</span></font><br>
生成器&迭代器
生成器:<span style="color: rgb(102, 102, 102); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px; white-space: pre-wrap;">generator</span>
<span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; line-height: 20px; white-space: nowrap; background-color: rgb(250, 250, 250);">yield</span>
迭代器
Iterator
iter():可以使用内建函数iter()来获取它的迭代器对象