import time
def performance(f):
def fn(*args, **kw):
print 'call' + f.__name__ + '() in,' ,time.time()
return f(*args, **kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
def performance(f):
def fn(*args, **kw):
print 'call' + f.__name__ + '() in,' ,time.time()
return f(*args, **kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
2018-03-07
class BStudent(Student,BasketballMixin):
def __init__(self):
super(BStudent,self).__init__()
class FTeacher(Teacher,FootballMixin):
def __init__(self):
super(FTeacher,self).__init__()
s = BStudent()
print s.skill()
t = FTeacher()
print t.skill()
def __init__(self):
super(BStudent,self).__init__()
class FTeacher(Teacher,FootballMixin):
def __init__(self):
super(FTeacher,self).__init__()
s = BStudent()
print s.skill()
t = FTeacher()
print t.skill()
2018-03-07
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-03-07
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-03-07
def cmp_ignore_case(s1, s2):
if str.lower(s1) > str.lower(s2):
return 1
elif str.lower(s1) < str.lower(s2):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if str.lower(s1) > str.lower(s2):
return 1
elif str.lower(s1) < str.lower(s2):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-03-07
import math
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
2018-03-07
def cmp_ignore_case(s1, s2):
if s1.capitalize() > s2.capitalize():
return 1
if s1.capitalize() < s2.capitalize():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.capitalize() > s2.capitalize():
return 1
if s1.capitalize() < s2.capitalize():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-03-07
import math
def is_sqr(x):
return x and math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
and也可以吧?
def is_sqr(x):
return x and math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
and也可以吧?
2018-03-06
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
2018-03-06
import math
def c(s1):
return s1.lower()
print(sorted(['bob', 'about', 'Zoo', 'Credit'],key=c,reverse=True))
def c(s1):
return s1.lower()
print(sorted(['bob', 'about', 'Zoo', 'Credit'],key=c,reverse=True))
2018-03-05