def f(s):
return s[0].upper()+s[1:].lower()
print map(f, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(f, ['adam', 'LISA', 'barT'])
2018-05-08
方法一:
import math
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
方法二:
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
import math
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
方法二:
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
2018-05-08
def calc_prod(lst):
def calc_a():
def a(x,y):
return x*y
return reduce(a,lst)
return calc_a
f = calc_prod([1, 2, 3, 4])
print f()
def calc_a():
def a(x,y):
return x*y
return reduce(a,lst)
return calc_a
f = calc_prod([1, 2, 3, 4])
print f()
2018-05-08
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower() :
return 1
if s1.lower()<s2.lower() :
return -1
return
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower()>s2.lower() :
return 1
if s1.lower()<s2.lower() :
return -1
return
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-05-08
import math
def is_sqr(x):
if math.sqrt(x)==int(math.sqrt(x)):
return x*x
print filter(is_sqr, range(1,101))
def is_sqr(x):
if math.sqrt(x)==int(math.sqrt(x)):
return x*x
print filter(is_sqr, range(1,101))
2018-05-08
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2018-05-08
方法一:
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2018-05-08
方法二:
l_o = ['adman', 'LISA', 'batT']
def format(s):
l_n = s[0].upper()
for i in s[1:]:
l_n = l_n + i.lower()
return l_n
print map(format, l_o)
l_o = ['adman', 'LISA', 'batT']
def format(s):
l_n = s[0].upper()
for i in s[1:]:
l_n = l_n + i.lower()
return l_n
print map(format, l_o)
2018-05-08
l_o = ['adman', 'LISA', 'batT']
l_n = []
for s in l_o:
s_n = s.capitalize()
l_n.append(s_n)
print l_n
l_n = []
for s in l_o:
s_n = s.capitalize()
l_n.append(s_n)
print l_n
2018-05-08
def format_name(s):
m=s[0:1:].upper()
for i in s[1:]:
m=m+i.lower()
return m
print map(format_name, ['adam', 'LISA', 'barT'])
m=s[0:1:].upper()
for i in s[1:]:
m=m+i.lower()
return m
print map(format_name, ['adam', 'LISA', 'barT'])
2018-05-08
def __cmp__(self, s):
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
return cmp(self.name, s.name)
if self.score > s.score:
return -1
elif self.score < s.score:
return 1
else:
return cmp(self.name, s.name)
2018-05-07
已采纳回答 / qq_sl_study
from math import sqrtf=sqrt def add(x, y, f): return f(x) + f(y) print add(25, 9, f) 或者import mathf=math.sqrt def add(x, y, f): return f(x) + f(y) print add(25, 9, f)
2018-05-07