class Fib(object):
data = [0,1,1,2,3,5,8]
def __init__(self, num):
self.num = num
while( len(Fib.data) < num):
Fib.data.append(sum(Fib.data[-2:]))
def __len__(self):
return self.num
def __str__(self):
return str(Fib.data[:self.num])
data = [0,1,1,2,3,5,8]
def __init__(self, num):
self.num = num
while( len(Fib.data) < num):
Fib.data.append(sum(Fib.data[-2:]))
def __len__(self):
return self.num
def __str__(self):
return str(Fib.data[:self.num])
2015-05-21
print filter(lambda s:s and len(s.strip())>0, ['test', None, '', 'str', ' ', 'END'])
2015-05-21
def calc_prod(lst):
def prod(x,y):
return x*y
def lazy_product():
return reduce(prod,lst)
return lazy_product
def prod(x,y):
return x*y
def lazy_product():
return reduce(prod,lst)
return lazy_product
2015-05-21
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
2015-05-21
def is_sqr(x):
if math.sqrt(x)%1==0:
return x
print filter(is_sqr, range(1, 101))
if math.sqrt(x)%1==0:
return x
print filter(is_sqr, range(1, 101))
2015-05-21
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2015-05-21