过滤器不返回构造或匹配的列表

时间:2016-11-03 15:37:54

标签: python

此刻我正在了解lambdafilter,所以我想知道是否有人可以帮助我理解我在以下 2 片段中做错了什么结果只打印为<filter object at 0x105762668>而不是我期望看到的结果:

my_list = range(16)

print( filter(lambda x: x % 3 == 0, my_list) )

# Expected to see [0, 3, 6, 9, 12, 15]



mylist = ["dog", "cat", "wildcat", "thundercat", "cow", "hooo"]

r = re.compile(".*cat")

newlist = filter(r.match, mylist)

print(newlist)

# Expected to see ["cat", "wildcat", "thundercat"]

0 个答案:

没有答案