zoukankan      html  css  js  c++  java
  • Python无限元素列表实例教程

    有关Python中无限元素列表的实现方法。

    本文实例讲述了Python怎么实现无限元素列表的方法,具体实现可使用Yield来完成。
    下面所述的2段实例代码通过Python Yield 生成器实现了简单的无限元素列表。(www.jbxue.com)
    1.递增无限列表
    具体代码:
    def increment():
    i = 0
    while True:
    yield i
    i += 1

    for j in increment():
    print i
    if (j > 10) : break

    2.斐波那契无限列表
    具体代码:
    def fibonacci():
    i = j = 1
    while True:
    result, i, j = i, j, i + j
    yield result

    for k in fibonacci():
    print k
    if (k > 100) : break

  • 相关阅读:
    JZOJ.2117. 【2016-12-30普及组模拟】台风
    团队合作
    长沙游记
    统计
    html....
    OI之路
    三鑫普及组模拟赛
    牛顿迭代法
    台风
    gcd
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3921168.html
Copyright © 2011-2022 走看看