找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3893|回复: 4

[已回复] python递归迭代器问题

1

主题

4

帖子

4

积分

贫民

积分
4
克克怪 发表于 2017-3-11 16:17:24 | 显示全部楼层 |阅读模式
在网上看到一个递归迭代器始终没有看明白,有哪些大神给讲下执行的步骤,谢谢了!!

[color=rgb(170, 170, 170) !important]2

[color=rgb(170, 170, 170) !important]3

[color=rgb(170, 170, 170) !important]4

[color=rgb(170, 170, 170) !important]5

[color=rgb(170, 170, 170) !important]6

[color=rgb(170, 170, 170) !important]7

[color=rgb(170, 170, 170) !important]8

[color=rgb(170, 170, 170) !important]9

[color=rgb(170, 170, 170) !important]10

[color=rgb(170, 170, 170) !important]11


def[color=rgb(0, 111, 224) !important] [color=teal !important]permutations[color=rgb(51, 51, 51) !important]([color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important])[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]    if[color=rgb(0, 111, 224) !important] [color=teal !important]len[color=rgb(51, 51, 51) !important]([color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important])[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]==[color=rgb(0, 111, 224) !important] [color=rgb(0, 153, 153) !important]0[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]        yield[color=rgb(0, 111, 224) !important] [color=teal !important]li
[color=teal !important]    else[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]        for[color=rgb(0, 111, 224) !important] i[color=rgb(0, 111, 224) !important] in[color=rgb(0, 111, 224) !important] [color=teal !important]range[color=rgb(51, 51, 51) !important]([color=teal !important]len[color=rgb(51, 51, 51) !important]([color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important])[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]            [color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 153, 153) !important]0[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 45, 122) !important]i[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]=[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 45, 122) !important]i[color=rgb(51, 51, 51) !important],[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 153, 153) !important]0
[color=rgb(0, 111, 224) !important]            for[color=rgb(0, 111, 224) !important] [color=teal !important]item in[color=rgb(0, 111, 224) !important] [color=teal !important]permutations[color=rgb(51, 51, 51) !important]([color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 153, 153) !important]1[color=rgb(0, 111, 224) !important]:[color=rgb(51, 51, 51) !important])[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]                yield[color=rgb(0, 111, 224) !important] [color=rgb(51, 51, 51) !important][[color=rgb(0, 45, 122) !important]li[color=rgb(51, 51, 51) !important][[color=rgb(0, 153, 153) !important]0[color=rgb(0, 111, 224) !important] [color=rgb(0, 111, 224) !important]+[color=rgb(0, 111, 224) !important] [color=teal !important]item

for[color=rgb(0, 111, 224) !important] [color=teal !important]item in[color=rgb(0, 111, 224) !important] [color=teal !important]permutations[color=rgb(51, 51, 51) !important]([color=teal !important]range[color=rgb(51, 51, 51) !important]([color=rgb(0, 153, 153) !important]3[color=rgb(51, 51, 51) !important])[color=rgb(51, 51, 51) !important])[color=rgb(0, 111, 224) !important]:
[color=rgb(0, 111, 224) !important]    [color=teal !important]print[color=rgb(0, 111, 224) !important] [color=rgb(0, 45, 122) !important]item



我自己看的绕不出来了。。。。。。
回复

使用道具 举报

1

主题

4

帖子

4

积分

贫民

积分
4
克克怪  楼主| 发表于 2017-3-11 16:18:24 | 显示全部楼层
我去这什么情况,发个贴成这样的了
回复 支持 反对

使用道具 举报

50

主题

1057

帖子

1108

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1108

活跃会员热心会员最佳导师默默耕耘突出贡献优秀版主荣誉管理论坛元老

blueelwang 发表于 2017-3-13 19:01:14 | 显示全部楼层
克克怪 发表于 2017-3-11 16:18
我去这什么情况,发个贴成这样的了

从哪里粘贴过来的?
回复 支持 反对

使用道具 举报

1

主题

4

帖子

4

积分

贫民

积分
4
克克怪  楼主| 发表于 2017-3-13 19:43:07 | 显示全部楼层
复制 的代码 就成这样了
回复 支持 反对

使用道具 举报

1

主题

4

帖子

4

积分

贫民

积分
4
克克怪  楼主| 发表于 2017-3-13 19:44:05 | 显示全部楼层
def flattern(nested):
    try:
        for sublist in nested:
            for element in flattern(sublist):
                print('>>>>>>>>>>>>>', element)
                yield element
    except TypeError:
        print('---------', nested)
        yield nested
nested = [[1, 2], [3, 4], [5], 6]
for i in flattern(nested):
    print(i)

这个递归生成器实在是理解不了,哪位大神能说下执行的步骤,感谢!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表