import math
def is_sqr(x):
return math.sqrt(x)-int(math.sqrt(x))==0
print filter(is_sqr, range(1, 101))
更易懂的
def is_sqr(x):
return math.sqrt(x)-int(math.sqrt(x))==0
print filter(is_sqr, range(1, 101))
更易懂的
2015-08-09
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j * j
return g
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(j):
def g():
return j * j
return g
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-08-08
print sorted(['bob', 'about', 'Zoo', 'Credit'], key=str.lower)
2015-08-08
def format_name(s):
if isinstance(s,str):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
if isinstance(s,str):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-08-07
def cmp_ignore_case(s1, s2):
s1=s1[0].lower()
s2=s2[0].lower()
return cmp(s1, s2)
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
s1=s1[0].lower()
s2=s2[0].lower()
return cmp(s1, s2)
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-08-07
def calc_prod(lst):
def mult(x,y):
return x*y
def res():
return reduce(mult,lst)
return res
f = calc_prod([1, 2, 3, 4])
print f()
def mult(x,y):
return x*y
def res():
return reduce(mult,lst)
return res
f = calc_prod([1, 2, 3, 4])
print f()
2015-08-07
import math
def is_sqr(x):
m=str(math.sqrt(x))
L=m.split('.')
if int(L[1])==0:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
m=str(math.sqrt(x))
L=m.split('.')
if int(L[1])==0:
return x
print filter(is_sqr, range(1, 101))
2015-08-06
已采纳回答 / 5941
s if len(s.strip())>0就不符合语法规范,你还想语法正确?lambda s:要求后面的是一个关于s的表达式,你这是表达式?回去好好复习大学课程,会对你有帮助的。
2015-08-06