class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1.name, p2.name, p3.name]
L2 = sorted(L1)
print L2[0]
print L2[1]
print L2[2]
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1.name, p2.name, p3.name]
L2 = sorted(L1)
print L2[0]
print L2[1]
print L2[2]
2017-10-06
def calc_prod(lst):
def ji():
return reduce(lambda x,y:x*y,lst)
return ji
f = calc_prod([1, 2, 3, 4])
print f()
def ji():
return reduce(lambda x,y:x*y,lst)
return ji
f = calc_prod([1, 2, 3, 4])
print f()
2017-10-06
我对字符串处理的比较多,这个函数处理字符串很好用。举个例子。
list(filter(lambda x:True if x is not None and len(x.strip())>0 else False,ls))
list(filter(lambda x:True if x is not None and len(x.strip())>0 else False,ls))
2017-10-06
map(lambda x:x[0].upper()+x[1:].lower(), ['adam', 'LISA', 'barT'])
2017-10-06
import math
def is_sqr(x):
return (math.sqrt(x)).is_integer()
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return (math.sqrt(x)).is_integer()
print filter(is_sqr, range(1, 101))
2017-10-05
其实将分数的判断放在构造函数__init__()内 和放在成员函数get_grade()内都是可以的。因为每次创建实例(对象)的时候,总会先调用__init__()函数,这时执行分数的判断也是OK的。
2017-10-04
1=========a:6 b:8
2=========a:8 b:6
3=========a:6 b:2
4=========a:2 b:0
return (6/2,8/2)
2=========a:8 b:6
3=========a:6 b:2
4=========a:2 b:0
return (6/2,8/2)
2017-10-04