1
gotounix 2016-08-11 11:40:29 +08:00
next_number 函数中
it = filter(palindrome_check, it) |
3
mgna17 2016-08-11 12:01:11 +08:00
发帖的时候右下角选 markdown
代码这样贴: ``` 你的代码 ``` |
5
hitmanx 2016-08-11 12:08:07 +08:00 via iPhone
Filter 的第一个变量应该传个函数指针,你传的的是个函数调用,类型相当于是它的返回值,是 bool 的,所以说 bool not callable 。另外你是不是忘了把 int 转成 str 了,当调用 palindrome 时
|
7
lll9p 2016-08-11 12:57:32 +08:00
```
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-08-11 12:58:35 +08:00
palindrome_check 不是应该用 string == string[::-1] 来判断的吗
还有应该写成这样 filter(palindrome_check, it) |
9
getlost OP |
11
aitaii 2016-08-11 18:36:05 +08:00
``` python
def palindrome_check(n): string = str(n) return string == string[::-1] ``` |