filter函数使用,目的是清除一个序列中的空字符串
def empty(s):
return s and s.strip()
print(list(filter(empty,["A","","B"," "," C "])))
运行结果是这样的['A', 'B', ' C ']
问题1:and连接," C "不应该被filter函数返回吧
对这个理解是:这个and是怎么清除空字符串呢?它也清除了" ",但是把" C "返回了。与我刚开始理解的:s.strip之后,与原s通过and连接不符合true不返回相矛盾,因为" C "返回了