print filter(lambda s: s and len(s.strip()) > 0, ['test', None, '', 'str', ' ', 'END'])
2015-03-14
def calc_prod(lst):
def fn(x,y):
return x*y
def cal_result():
return reduce(fn,lst)
return cal_result
def fn(x,y):
return x*y
def cal_result():
return reduce(fn,lst)
return cal_result
2015-03-13
def cmp_ignore_case(s1, s2):
l1, l2 = (s1.lower(), s2.lower())
if l1 < l2:
return -1
if l1 > l2:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
l1, l2 = (s1.lower(), s2.lower())
if l1 < l2:
return -1
if l1 > l2:
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-03-13
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
2015-03-13
def format_name(s):
return s[:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[:1].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-03-13
def count():
fs = []
for i in range(1, 4):
fs.append(lambda i=i : i*i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
fs = []
for i in range(1, 4):
fs.append(lambda i=i : i*i)
return fs
f1, f2, f3 = count()
print f1(), f2(), f3()
2015-03-11