def cmp_ignore_case(s1, s2):
if s1[0].lower() > s2[0].lower():
return 1
if s1[0].lower() < s2[0].lower()
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
少几行代码还不错
if s1[0].lower() > s2[0].lower():
return 1
if s1[0].lower() < s2[0].lower()
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
少几行代码还不错
2016-06-15
class Person(object)
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
2016-06-14
python3.0用法
def cmp_ignore_case(s1):
return s1.lower()
print(sorted(['bob', 'about', 'Zoo', 'Credit'],key=cmp_ignore_case))
def cmp_ignore_case(s1):
return s1.lower()
print(sorted(['bob', 'about', 'Zoo', 'Credit'],key=cmp_ignore_case))
2016-06-14
def calc_prod(lst):
def cal():
return reduce(lambda x,y:x*y,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
def cal():
return reduce(lambda x,y:x*y,lst)
return cal
f = calc_prod([1, 2, 3, 4])
print f()
2016-06-13
__slots__ = ('name','gender','score')子类中限制属性和父类重复也没事啊
2016-06-13
def count():
fs = []
for i in range(1, 4):
def f():
return i * i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
fs = []
for i in range(1, 4):
def f():
return i * i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
2016-06-12