我的可能是最最麻烦的算法了:
def format(s):
out=s[0].upper()
b=1
c=len(s)
while True:
out=out+s[b].lower()
b=b+1
if b==len(s):
break
return out
def format(s):
out=s[0].upper()
b=1
c=len(s)
while True:
out=out+s[b].lower()
b=b+1
if b==len(s):
break
return out
2016-06-10
def calc_prod(lst):
def j():
y = 1
for x in lst:
y = x * y
return y
return j
def j():
y = 1
for x in lst:
y = x * y
return y
return j
2016-06-08
def cmp_ignore_case(s1, s2):
s1 = s1.lower()
s2 = s2.lower()
if s1 > s2:
return 1
elif s1 < s2:
return -1
return 0
s1 = s1.lower()
s2 = s2.lower()
if s1 > s2:
return 1
elif s1 < s2:
return -1
return 0
2016-06-08
这个循环呢,就是网fs中加入了三个函数,f1,f2,f3分别只想三个函数,如下所示。不改之前函数内容是[i*i,i*i,i*i],调用时,i=3;改之后是[m*m,m*m,m*m]调用时,m分别等于1,2,3。
count()
Out[24]: [<function __main__.f>, <function __main__.f>, <function __main__.f>]
count()
Out[24]: [<function __main__.f>, <function __main__.f>, <function __main__.f>]
2016-06-08
最新回答 / Ramon_Lee
if self.__score>=85:print u'A-优秀'elif self.__score>=60:print u'B-及格'else:print u'C-不及格'你使用 u'A-优秀' 能打印出结果吗?我的老报错,就是打印不出A-优秀,我的是python2
2016-06-08
L = ['test',None,'','str',' ','END']
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式 ,可读性更高
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式 ,可读性更高
2016-06-08
L = ['test',None,'','str',' ','END']
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式,可读性更高
>>> def f(s):
... return s and len(s.strip())>0
...
>>> filter(f,L)
['test', 'str', 'END']
用调用函数的形式,可读性更高
2016-06-08
import math
def is_sqr(x):
return str(math.sqrt(x))[-1] == '0'
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return str(math.sqrt(x))[-1] == '0'
print filter(is_sqr, range(1, 101))
2016-06-07