import math
def f(x):
if math.sqrt(x) % 1 == 0:
return x
print filter(f, range(1, 101))
def f(x):
if math.sqrt(x) % 1 == 0:
return x
print filter(f, range(1, 101))
2015-03-20
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-03-19
from operator import mul
def calc_prod(lst):
def prod():
return reduce(mul, lst, 1)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
def calc_prod(lst):
def prod():
return reduce(mul, lst, 1)
return prod
f = calc_prod([1, 2, 3, 4])
print f()
2015-03-19
import functools
sorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
sorted_ignore_case = functools.partial(sorted, cmp=lambda s1, s2: cmp(s1.upper(), s2.upper()))
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2015-03-19