最赞回答 / 宝慕林6305465
借用一切都是浮云何必刻苦铭心的答案:sorted(iterable[, cmp[, key[, reverse]]]) sorted 这个函数接受这3个关键词,key表示排序的元素,比如一个人的信息,可以从名字排序, 可以从年龄排序,这就...
2019-05-07
已采纳回答 / 人间世支离疏
t = time.ctime() *1000 if unit =='ms' else time.time()首先题目要求是获取计算时间第二time.ctime()返回易读的字符串模式的当前时间 t = time.ctime() *1000就肯定会出错,去掉*1000就不会打印了无数次 t
2019-05-06
# -*- coding:utf-8 -*-
class Person(object):
def __init__(self, name, score):
self.name=name
self.score=score
def get_grade(self):
if self.score<60:
return 'C不合格'
elif self.score<90:
return 'B合格'
else:
return 'A优秀'
class Person(object):
def __init__(self, name, score):
self.name=name
self.score=score
def get_grade(self):
if self.score<60:
return 'C不合格'
elif self.score<90:
return 'B合格'
else:
return 'A优秀'
2019-05-05
def count():
fs = []
for i in range(1, 4):
def f(n=i):
return n*n
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f(n=i):
return n*n
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2019-05-04
def count():
fs = []
for i in range(1, 4):
def f(i):
return lambda : i**2
fs.append(f(i))
return fs
for j in count():
print(j())
fs = []
for i in range(1, 4):
def f(i):
return lambda : i**2
fs.append(f(i))
return fs
for j in count():
print(j())
2019-05-04
try:
import simplejson as json
except ImportError:
import json as json
print json.dumps({'python':2.7})
import simplejson as json
except ImportError:
import json as json
print json.dumps({'python':2.7})
2019-05-02
def cmp_ignore_case(x, y):
if x.upper() > y.upper():
return 1
if x.upper() < y.upper():
return -1
return 0
def iterable(x, base=cmp_ignore_case):
return sorted(x, base)
sorted_ignore_case = functools.partial(iterable)
if x.upper() > y.upper():
return 1
if x.upper() < y.upper():
return -1
return 0
def iterable(x, base=cmp_ignore_case):
return sorted(x, base)
sorted_ignore_case = functools.partial(iterable)
2019-05-02
def wrapper(*args, **kw):
if unit=='ms':
print 'call',f.__name__ + '() in', long(1000*time.time()), 'ms'
else:
print 'call',f.__name__ + '() in', long(time.time()), 's'
return f(*args, **kw)
if unit=='ms':
print 'call',f.__name__ + '() in', long(1000*time.time()), 'ms'
else:
print 'call',f.__name__ + '() in', long(time.time()), 's'
return f(*args, **kw)
2019-05-02
import time
def performance(f):
def fn(x):
print 'call',f.__name__ + '() in', time.time()
return f(x)
return fn
def performance(f):
def fn(x):
print 'call',f.__name__ + '() in', time.time()
return f(x)
return fn
2019-05-02
def count():
fs = []
def f(x):
return x*x
for i in range(1, 4):
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1, f2, f3
fs = []
def f(x):
return x*x
for i in range(1, 4):
fs.append(f(i))
return fs
f1, f2, f3 = count()
print f1, f2, f3
2019-05-02