def test_foldr(self):
"""
Apply a function of two arguments cumulatively to the items of
a sequence, from right to left, so as to reduce the sequence to
a single value.
"""
self.assertEqual(
irc._foldr(operator.sub, 0, [1, 2, 3, 4]),
-2)
def insertTop(l, x):
l.insert(0, x)
return l
self.assertEqual(
irc._foldr(insertTop, [], [[1], [2], [3], [4]]),
[[[[[], 4], 3], 2], 1])
评论列表
文章目录