a*****n 发帖数: 682 | 1 只用过很短时间的python,面试的那家发来一些题目,其中一道是关于python的,能帮
忙解答一下吗?谢谢
There's a problem with the following Python 2.x code, please fix it.
print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: x*x,
xrange(10**6)))) = sum(x*x for x in xrange(1, 10**6, 2))
After the fix, what would be printed? Explain the result. | d********g 发帖数: 10550 | 2 = 改为 ==
print结果应该为True
这题就是考reduce()、filter()、map(),然后lambda
先map一个y=x^2给xrange(10^6),然后把list通过filter留下x为奇数的情况,再用
reduce全部加起来,应该等于直接sum一个步进为2的x^2 list(奇数x^2 list)
另外考这道题属于蛋疼
【在 a*****n 的大作中提到】 : 只用过很短时间的python,面试的那家发来一些题目,其中一道是关于python的,能帮 : 忙解答一下吗?谢谢 : There's a problem with the following Python 2.x code, please fix it. : print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: x*x, : xrange(10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) : After the fix, what would be printed? Explain the result.
| a*****n 发帖数: 682 | 3 改为什么?
【在 d********g 的大作中提到】 : = 改为 == : print结果应该为True : 这题就是考reduce()、filter()、map(),然后lambda : 先map一个y=x^2给xrange(10^6),然后把list通过filter留下x为奇数的情况,再用 : reduce全部加起来,应该等于直接sum一个步进为2的x^2 list(奇数x^2 list) : 另外考这道题属于蛋疼
| d********g 发帖数: 10550 | 4 "="改为"=="
= sum
改成
== sum
【在 a*****n 的大作中提到】 : 改为什么?
|
|