Discuss / Python / 记录一下

记录一下

Topic source

XHS_12302

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-

def triangles():

    L = [0, 1, 0]
    while True:
        yield [y for y in L if y != 0]
        L = [x if i == 0 else L[i -1] + L[i]  for i, x in enumerate(L)]
        L.append(0)

XHS_12302

#2 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-

def triangles():

    L = [0, 1, 0]
    while True:
        yield [y for y in L if y != 0]
        L = [x if i == 0 else L[i -1] + L[i]  for i, x in enumerate(L) + [0]  # 将append(0) 改为 + 号追加元素


XHS_12302

#3 Created at ... [Delete] [Delete and Lock User]
# 第二个记录,由于一时大意,手误多删了一个符号。 在末尾 '+ [0]' 前面缺少了半个 ']' ,

  • 1

Reply