from functools import reduce
def calc_prod(lst):
def quad():
return reduce(ji,lst)
return quad
def ji(x,y):
return x * y
f = calc_prod([1, 2, 3, 4])
print(f())
哎还是学py3吧
def calc_prod(lst):
def quad():
return reduce(ji,lst)
return quad
def ji(x,y):
return x * y
f = calc_prod([1, 2, 3, 4])
print(f())
哎还是学py3吧
2020-06-19
import numpy
def calc_prod(lst):
return numpy.prod(lst)
f = calc_prod([1, 2, 3, 4])
print(f)
def calc_prod(lst):
return numpy.prod(lst)
f = calc_prod([1, 2, 3, 4])
print(f)
2020-06-18
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2020-06-09
def __cmp__(self, s):
if self.score<s.score:
return 1
if self.score>s.score:
return -1
if self.score==s.score:
if self.name>s.name:
return 1
if self.name<s.name:
return -1
return 0
if self.score<s.score:
return 1
if self.score>s.score:
return -1
if self.score==s.score:
if self.name>s.name:
return 1
if self.name<s.name:
return -1
return 0
2020-06-06
%d 整数
%f 浮点数
%s 字符串
%x 十六进制整数
使用方法:
tpl = "i am %s" % "alex"
tpl = "i am %s age %d" % ("alex", 18)
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
tpl = "percent %.2f" % 99.97623
tpl = "i am %(pp).2f" % {"pp": 123.425556, }
tpl = "i am %.2f %%" % {"pp": 123.425556, }
%f 浮点数
%s 字符串
%x 十六进制整数
使用方法:
tpl = "i am %s" % "alex"
tpl = "i am %s age %d" % ("alex", 18)
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
tpl = "percent %.2f" % 99.97623
tpl = "i am %(pp).2f" % {"pp": 123.425556, }
tpl = "i am %.2f %%" % {"pp": 123.425556, }
2020-06-06
占位符%s既可以表示字符串str,还可以表示整数int,浮点数float;
占位符%d既可以表示整数int,还可以表示浮点数float(去除整数部分)
占位符%f既可以表示浮点数float,还可以表示整数int(默认保留6位小数)
注意:若想自主保留n位小数,可将其表示位%.nf
占位符%d既可以表示整数int,还可以表示浮点数float(去除整数部分)
占位符%f既可以表示浮点数float,还可以表示整数int(默认保留6位小数)
注意:若想自主保留n位小数,可将其表示位%.nf
2020-06-06
import math
def is_sqr(x):
return math.sqrt(x) in range(1,11)
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) in range(1,11)
print filter(is_sqr, range(1, 101))
2020-05-23
def calc_prod(lst):
def cprod():
x = 1
for n in lst:
x = n * x
return x
return cprod
f = calc_prod([1, 2, 3, 4])
print f()
def cprod():
x = 1
for n in lst:
x = n * x
return x
return cprod
f = calc_prod([1, 2, 3, 4])
print f()
2020-05-12
def calc_prod(lst):
def cheng(x,y):
return x*y
def fiterinfo():
return reduce(cheng,lst)
return fiterinfo
f = calc_prod([1, 2, 3, 4])
print f()
def cheng(x,y):
return x*y
def fiterinfo():
return reduce(cheng,lst)
return fiterinfo
f = calc_prod([1, 2, 3, 4])
print f()
2020-05-02
def cmp_ignore_case(s1, s2):
if(s1[0].lower()>s2[0].lower()):
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if(s1[0].lower()>s2[0].lower()):
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2020-05-02