此刻我正在了解lambda
和filter
,所以我想知道是否有人可以帮助我理解我在以下 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"]