num=[1,99,2,3,44,77,333,22,44]
print(sorted(num,reverse=True))
python3.x
print(sorted(num,reverse=True))
python3.x
2017-11-21
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2017-11-21
def calc_prod(lst):
def Z(x,y):
return x*y
return reduce(Z,lst)
f = calc_prod([1, 2, 3, 4])
print f
def Z(x,y):
return x*y
return reduce(Z,lst)
f = calc_prod([1, 2, 3, 4])
print f
2017-11-21
def cmp_ignore_case(s1, s2):
if s1[0].upper() > s2[0].upper():
return 1
if s1[0].upper() < s2[0].upper():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].upper() > s2[0].upper():
return 1
if s1[0].upper() < s2[0].upper():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-11-21
from math import *
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, sqrt)
2017-11-20
import math
def is_sqr(x):
if int(math.sqrt(x)) * int(math.sqrt(x)) == x :
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if int(math.sqrt(x)) * int(math.sqrt(x)) == x :
return x
print filter(is_sqr, range(1, 101))
2017-11-20
def calc_prod(lst):
def prod( ):
summ=1
for l in lst:
summ=summ*l
return summ
return prod
f = calc_prod([1, 2, 3, 4])
print f( )
def prod( ):
summ=1
for l in lst:
summ=summ*l
return summ
return prod
f = calc_prod([1, 2, 3, 4])
print f( )
2017-11-20
def calc_prod(lst):
def lazy_prod(x,y):
return x*y
def prod():
return reduce(lazy_prod,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_prod(x,y):
return x*y
def prod():
return reduce(lazy_prod,lst)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-11-20
def cmp_ignore_case(s1, s2):
u1=s1[:].upper()
u2=s2[:].upper()
return cmp(u1,u2)
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
u1=s1[:].upper()
u2=s2[:].upper()
return cmp(u1,u2)
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-11-20
这是三层关系,第一层只接受了变量,第二层才接收函数。所以放在第二层开始位置即可
def performance(unit):
def perf_decorator(f):
@functools.wraps(f)
def performance(unit):
def perf_decorator(f):
@functools.wraps(f)
2017-11-20