用filter来判断素数,提示<filter object at 0x03DFDA60>,发现filter的结果是一个数组 需要 list 。
将print(newlist)修改为print(list(newlist)),修改后:
def is_odd(n):
return n % 2 == 1
seq = [11,10,9,9,10,10,9,8,23,9,7,18,12,11,12]
newlist = filter(is_odd,seq)
print(list(newlist))
执行结果:
[11, 9, 9, 9, 23, 9, 7, 11]