摘要:
据说是外国某个公司的题目。那么这一坨代码到底是啥呢?g = lambda x,y: lambda x: (-1 / y)* x + y先print g, 原来是一个函数对象。那么试试 g(0, 1)还是一个对象。好吧,把它改造一下:def otter_function(x, y): def inner_function(x): return (-1 / y) * x + y return inner_function这样就比较好看了,然后加个函数参数,调用一下.def otter_function(x, y): print locals() def inn... 阅读全文
posted @ 2013-12-29 16:58
jaw-crusher
阅读(171)
评论(0)
推荐(0)
摘要:
可以使用列表解析+count简单实现:def get_ele(alist): return [i for i in alist if alist.count(i) == 2][0]print get_ele([1,2,3,-1,-1])一个列表中只有一个数字出现了一次,其他都出现了两次,可以这么写, 利用异或运算的性质:get_once_ele = lambda alist: reduce(lambda a,b: a ^ b, alist)print get_once_ele([2, 2, 1, 1, 4])print get_once_ele([1, 1, 0, 2, 3, 2, 3]... 阅读全文
posted @ 2013-12-29 16:07
jaw-crusher
阅读(347)
评论(0)
推荐(0)

浙公网安备 33010602011771号