直接上代码,类似与swift
#! /usr/bin/env python
#def add(x,y,f): # return f(x)+f(y); #print (add(-5,-10,abs)); #def format_name(s): # return s[0].upper() + s[1:].lower(); #print map(format_name,['adam', 'LISA', 'barT']) #def prod(x, y): # return x*y #print reduce(prod, [2, 3,4, 5],10) #import math #def is_sqr(x): # r = int(math.sqrt(x)) # return r*r==x #print filter(is_sqr, range(1, 101)) def is_not_empty(s):
return s and len(s.strip()) > 0
print filter(is_not_empty, ['test', None, '', 'str', ' ', 'END'])
"""def cmp_ignore_case(s1, s2): u1 = s1.upper() u2 = s2.upper() if u1 < u2: return -1 if u1 > u2: return 1 return 0 print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case) """