摘要:
首先贴出Python编写的汉诺塔算法的代码: def hanoti(n,x1,x2,x3): if(n == 1): print('move:',x1,'-->',x3) return hanoti(n-1,x1,x3,x2) print('move:',x1,'-->',x3) hanoti(n- 阅读全文
posted @ 2016-09-23 21:50
埃木贼
阅读(10208)
评论(0)
推荐(2)
摘要:
可用于for循环的对象称为可迭代对象(Iterable),可迭代对象分为: 1.集合数据类型:list、turple、dict、set、dir等 2.generator,包括:生成器和生成器函数 可调用next()函数并不断返回下一值的对象称为迭代器(Iterator) 生成器都是Iterator对 阅读全文
posted @ 2016-09-23 21:32
埃木贼
阅读(189)
评论(0)
推荐(0)
摘要:
生成器也是一种迭代器,可以用于Python的for循环中; 生成迭代器的方法很简单:把一个列表生成式中的[]换成()就创造了一个生成器; yield关键字标志着函数变为生成器函数; 调用next()方法时,遇到yield生成器函数停止执行(挂起),并将yield后的值作为next()的返回值,可以这 阅读全文
posted @ 2016-09-23 21:03
埃木贼
阅读(115)
评论(0)
推荐(0)