1
gotounix 2016 年 8 月 11 日
next_number 函数中
it = filter(palindrome_check, it) |
3
mgna17 2016 年 8 月 11 日
发帖的时候右下角选 markdown
代码这样贴: ``` 你的代码 ``` |
5
hitmanx 2016 年 8 月 11 日 via iPhone
Filter 的第一个变量应该传个函数指针,你传的的是个函数调用,类型相当于是它的返回值,是 bool 的,所以说 bool not callable 。另外你是不是忘了把 int 转成 str 了,当调用 palindrome 时
|
7
lll9p 2016 年 8 月 11 日
```
def number_generator(): n = 11 while True: yield n n = n + 1 def palindrome_check(n): string = str(n) # .... return string == string[::-1] def next_number(): it = number_generator() while True: n = next(it) yield n # .... it = filter(palindrome_check, it) for a in next_number(): if a < 1000: print(a) else: break ``` |
8
lll9p 2016 年 8 月 11 日
palindrome_check 不是应该用 string == string[::-1] 来判断的吗
还有应该写成这样 filter(palindrome_check, it) |
9
getlost OP |
11
aitaii 2016 年 8 月 11 日
``` python
def palindrome_check(n): string = str(n) return string == string[::-1] ``` |