def prod(x,y):
return x*y;
def calc_prod(lst):
def lazy_calc_prod():
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
return x*y;
def calc_prod(lst):
def lazy_calc_prod():
return reduce(prod,lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-03-08
class Fib(object):
def __init__(self, num):
self.num = [0, 1]
for i in range(0, num - 2):
self.num.append(self.num[i] + self.num[i + 1])
def __len__(self):
return len(self.num)
def __str__(self):
return str(self.num)
f = Fib(10)
print (f)
def __init__(self, num):
self.num = [0, 1]
for i in range(0, num - 2):
self.num.append(self.num[i] + self.num[i + 1])
def __len__(self):
return len(self.num)
def __str__(self):
return str(self.num)
f = Fib(10)
print (f)
2016-03-07
def count():
fs = []
for i in range(1, 4):
def f():
int y
y=i*i
return y
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
def f():
int y
y=i*i
return y
fs.append(f)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2016-03-07
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-03-06
import math
def is_sqr(x):
if math.sqrt(x)%1==0:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x)%1==0:
return x
print filter(is_sqr, range(1, 101))
2016-03-06
def cmp_ignore_case(s1, s2):
if s1.lower>s2.lower:
return 1
if s1.lower<s2.lower:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower>s2.lower:
return 1
if s1.lower<s2.lower:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-03-06
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])
2016-03-06