Discuss / Python / 参考评论的三种方法

参考评论的三种方法

Topic source

空城已去

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

# #第一种方法,非generator方法
# ################################################
# def triangles(row):
#     x = [[0 for s in range(i+1)] for i in range(row)]
#     for n in range(0,row):
#         for m in range(n+1):
#             if m == 0 or m == n:
#                 x[n][m] = 1
#             else:
#                 x[n][m] = x[n-1][m-1] + x[n-1][m]
#     yield x
# ####################################################
# for each in triangles(5):
#     print(each)
# ######################################################


#第二种方法
#######################################################
# def triangles(row):
#     L = [1]
#     yield(L)
#     L = [1,1]
#     yield(L)
#     while len(L) <= row:
#         L = [1] + [L[i] + L[i + 1] for i in range(len(L) - 1)] + [1]
#         yield L
#######################################################
# for i in triangles(5):
#     print(i)
##########################################################


#第三种方法
# def triangles(row):
#     L = [1]
#     yield(L)
#     L = [1,1]
#     yield(L)
#     while len(L) <= row:
#         L1 = L[:]
#         L2 = L[:]
#         L1.insert(0,0)
#         L2.append(0)    
#         L = [L1[i] + L2[i] for i in range(len(L) + 1)]
#         yield(L)
######################################################
# for i in triangles(5):
#     print(i)

fressman

#2 Created at ... [Delete] [Delete and Lock User]

真膜拜你 居然写了三个方法 厉害


  • 1

Reply