import functools
def bf (s1,s2):
if(s1.lower() < s2.lower()):
return -1
if(s1.lower() > s2.lower()):
return 1
return 0
sorted_ignore_case = functools.partial(sorted,cmp = bf)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
def bf (s1,s2):
if(s1.lower() < s2.lower()):
return -1
if(s1.lower() > s2.lower()):
return 1
return 0
sorted_ignore_case = functools.partial(sorted,cmp = bf)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2015-08-01
def __str__(self):
if self.q == 1:
return '%s'%self.p
else:
return '%s/%s'%(self.p,self.q)
if self.q == 1:
return '%s'%self.p
else:
return '%s/%s'%(self.p,self.q)
2015-08-01
def Gcd(self,p,q):
if q == 0:
return p
else:
return self.Gcd(q,p%q)
if q == 0:
return p
else:
return self.Gcd(q,p%q)
2015-08-01
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
靠!这样岂不是更简单。。。。
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
靠!这样岂不是更简单。。。。
2015-07-31
def CMP(inputX):
check = {90:'A',60:'B'}
for k in check.iterkeys():
if cmp(inputX,k)>=0:
return check[k]
else:
return 'C'
----------------------------------------
def get_grade(self):
return CMP(self.__score)
check = {90:'A',60:'B'}
for k in check.iterkeys():
if cmp(inputX,k)>=0:
return check[k]
else:
return 'C'
----------------------------------------
def get_grade(self):
return CMP(self.__score)
2015-07-30
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', 'Student') they are the same effect
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', 'Student') they are the same effect
2015-07-30
请问为何在python3上会出现TypeError: must use keyword argument for key function这个问题呢!老师啥时候出个python3的课程呢
2015-07-30
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-07-29