
反向迭代列表
-
方法1,问题:破坏原列表
Paste_Image.png
-
方法2,问题:浪费空间
Paste_Image.png
-
方法3(推荐)
reversed得到列表的反向迭代器
Paste_Image.png
相反于iter,得到列表的正向迭代器

程序如下,既列表的反向迭代

iter函数调用iter方法,reversed函数调用reversed方法

实现函数

测试用例

结果

反向迭代测试用例

结果

方法1,问题:破坏原列表
方法2,问题:浪费空间
方法3(推荐)
reversed得到列表的反向迭代器
相反于iter,得到列表的正向迭代器
程序如下,既列表的反向迭代
iter函数调用iter方法,reversed函数调用reversed方法
实现函数
测试用例
结果
反向迭代测试用例
结果
本文标题:3-4 如何进行反向迭代以及如何实现反向迭代
本文链接:https://www.haomeiwen.com/subject/mlkzuttx.html
网友评论