map is useless!
Lie Ryan
lie.1296 at gmail.com
Sun Jun 6 20:16:19 EDT 2010
On 06/07/10 09:56, D'Arcy J.M. Cain wrote:
> On Mon, 07 Jun 2010 05:59:02 +1000
> Lie Ryan <lie.1296 at gmail.com> wrote:
>>> foo = lambda x: [y + 1 for y in x]
>>> [foo(x) for x in [[4, 6, 3], [6, 3, 2], [1, 3, 5]]]
>>>
>>> Didn't seem like such a long walk.
>>>
>>
>> that's because you're simplifying the problem, the correct walk is:
>
> Well, since it gives the same answer and you didn't actually state the
> problem I'm not sure how you can make that statement.
>
> Show me the unit test that defines the problem.
that you must use foo() and you can't change foo() (since foo is very
complex), and you give the same result as the original solution.
def solution(lst):
# make changes here only
return foo(map, lst)
def foo(func, args):
g = lambda x: x+1
return [func(g, x) for x in args]
import unittest
@unittest.FunctionTestCase
def test():
lst = [[4, 6, 3], [6, 3, 2], [1, 3, 5]]
ans = [[5, 7, 4], [7, 4, 3], [2, 4, 6]]
test.assertEqual(solution(lst), ans)
test.runTest()
More information about the Python-list
mailing list