Discuss / Python / 用匿名函数改写count()

用匿名函数改写count()

Topic source

葛斯特

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding = utf-8 -*-
def count():
    fs = []
    def f(j):
        return lambda : j ** 2
    for i in range(1, 4):
        fs.append(f(i))
    return fs

f1, f2, f3 = count()
print(f1(), f2(), f3())

  • 1

Reply