想了很久无奈只能这样了?
def count():
fs = []
index = []
for i in range(1, 4):
def f():
result = index[0] * index[0]
index.pop(0)
return result
fs.append(f)
index.append(i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
def count():
fs = []
index = []
for i in range(1, 4):
def f():
result = index[0] * index[0]
index.pop(0)
return result
fs.append(f)
index.append(i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2018-10-12
import math
def is_sqr(x):
return str(math.sqrt(x))[-2:]=='.0'
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return str(math.sqrt(x))[-2:]=='.0'
print filter(is_sqr, range(1, 101))
2018-10-11
最赞回答 / 零空飞翔
我的理解是两个值 x,y比较,1和-1决定的是列表的排序方式。当u1>u2时,如果你想让列表排序由小到大排的话,就返回1(对应规则中的 如果x排在y后面,返回1);若你想让列表排序由大到小排的话,就返回-1(对应规则中的 如果x排在y前面,返回-1)
2018-10-10
def cmp_ignore_case(s1, s2):
ss1= s1.lower()
ss2= s2.lower()
if ss1 > ss2:
return 1
if ss1 < ss2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
ss1= s1.lower()
ss2= s2.lower()
if ss1 > ss2:
return 1
if ss1 < ss2:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-10-09
import math
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1, 101))
2018-10-09
最新回答 / lujinyi666
from functools import reducedef proc(x,y): return x*yprint (reduce (proc,[2,4,5],10))#Python 37的运行结果为400
2018-10-09