class Person(object):
def __init__(self,name,gender,birth,**kw):
self.name = name
self.gender = gender
self.birth = birth
for k,v in kw.items():
setattr(self,k,v)
def __init__(self,name,gender,birth,**kw):
self.name = name
self.gender = gender
self.birth = birth
for k,v in kw.items():
setattr(self,k,v)
2015-09-06
def cmp_ignore_case(s1, s2):
if ord(s1[0].lower()) <= ord(s2[0].lower()):
return -1
else:
return 1
print sorted(['bob','about','Zoo','Credit'],cmp_ignore_case)
if ord(s1[0].lower()) <= ord(s2[0].lower()):
return -1
else:
return 1
print sorted(['bob','about','Zoo','Credit'],cmp_ignore_case)
2015-09-05
import math
def is_sqr(x):
if math.sqrt(x)%1 == 0:
return True
else:
return False
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x)%1 == 0:
return True
else:
return False
print filter(is_sqr, range(1, 101))
2015-09-05
def format_name(s):
return s.lower().title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.lower().title()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-09-04
最赞回答 / lifelegendc
cmp是sorted()的参数,就像int(a,b)中的b一样,比如,你调用int (),使用的是2进制转换,则里面的参数是int(a,base=2),因此sorted中的cmp=就跟这里的base=一样。
2015-09-04
import json
class Students(object):
def __init__(self,lists):
self.lists=lists
def read(self):
return self.lists.lower()
L=r'["Time","Bob","Alice"]'
s = Students(L)
print json.load(s)
明明输出是正确的,但是就是不给我通过,求解释啊
class Students(object):
def __init__(self,lists):
self.lists=lists
def read(self):
return self.lists.lower()
L=r'["Time","Bob","Alice"]'
s = Students(L)
print json.load(s)
明明输出是正确的,但是就是不给我通过,求解释啊
2015-09-04
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])
2015-09-02
import math
def is_sqr(x):
if( math.sqrt(x) * 10)%10==0:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if( math.sqrt(x) * 10)%10==0:
return x
print filter(is_sqr, range(1, 101))
2015-09-02
def cmp_ignore_case(s1, s2):
if s1[0].upper() > s2[0].upper():
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].upper() > s2[0].upper():
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-09-02
最赞回答 / qq_自然辩证_0
pass就是什么也不做,只是为了防止语法错误,比如:if a>1: pass #我这里先不做任何处理,直接跳过,但是如果不写pass,就会语法错误
2015-09-01