python 笔试题
2016-12-04 17:07
309 查看
1. 编写一个函数求 Fibonacci 数列第 n 项。
fib=lambda n,x=0,y=1:x if n <2 else fib(n-1,y,x+y)
2. 编写一个函数,判定某个数 n 是否为 2 的整数次幂。
def judge(n):
return True if not (n>>1)&n else False
judge=lambda n:True if not (n>>1)&n else False
3. 用 reduce 函数实现 map 函数。
def remap(func,src):
return reduce(lambda x,y:x+[func(y)],src,[])
4. 有一表格,长 6 步,宽 7 步。从左上角至有下角,共有多少种可能的路径?
C(13,6) =1716
5. 实现下列函数,求给定序列中元素的指定组合:
def combin(l, n):
'''
>>> combin(list(range(1, 5)), 3)
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
>>> list(map(lambda x: ''.join(x), combin("world", 3))))
['wor', 'wol', 'wod', 'wrl', 'wrd', 'wld', 'orl', 'ord', 'old', rld']
'''
pass
def comb(l,n):
res=[]
tmp=[0]*n
def fill_tmp(start=0,count=0):
if count==n :
res.append(copy.copy(tmp))
return
for j in xrange(start,len(l)):
if count <= n-1:
tmp[count]=l[j]
fill_tmp(j+1,count+1)
fill_tmp()
return res;
fib=lambda n,x=0,y=1:x if n <2 else fib(n-1,y,x+y)
2. 编写一个函数,判定某个数 n 是否为 2 的整数次幂。
def judge(n):
return True if not (n>>1)&n else False
judge=lambda n:True if not (n>>1)&n else False
3. 用 reduce 函数实现 map 函数。
def remap(func,src):
return reduce(lambda x,y:x+[func(y)],src,[])
4. 有一表格,长 6 步,宽 7 步。从左上角至有下角,共有多少种可能的路径?
C(13,6) =1716
5. 实现下列函数,求给定序列中元素的指定组合:
def combin(l, n):
'''
>>> combin(list(range(1, 5)), 3)
[[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
>>> list(map(lambda x: ''.join(x), combin("world", 3))))
['wor', 'wol', 'wod', 'wrl', 'wrd', 'wld', 'orl', 'ord', 'old', rld']
'''
pass
def comb(l,n):
res=[]
tmp=[0]*n
def fill_tmp(start=0,count=0):
if count==n :
res.append(copy.copy(tmp))
return
for j in xrange(start,len(l)):
if count <= n-1:
tmp[count]=l[j]
fill_tmp(j+1,count+1)
fill_tmp()
return res;
相关文章推荐
- 笔试 - 高德软件有限公司python试题 及 答案
- 快速深入一门语言的几个问题(Python面试题、笔试题、快速深入一门语言的绝招)
- python几道笔试题
- 关于Python笔试中提交代码多组测试的输入问题汇总
- 2017校招去哪网,阿里,网易,中兴,华为笔试编程题五则(Python描述)
- C/Python实现的一道笔试题
- 笔试 - 高德软件有限公司python问题 和 答案
- Python在线笔试琐碎
- 【笔试/面试】—— Python 古怪语法题
- 几道python笔试题
- Python笔试题目:求最大的K个数子,解法一,最快速实现的方法
- Python算法笔试题目,破解Hash值,N进制法
- [pptv]笔试题——字符串匹配 python
- Python笔试题目:求最大的K个数子,解法二,适合小型数据集的情况
- 【实习】暑期实习之python笔试题(一)
- 整理的一些PYTHON笔试面试题目
- 笔试测试开发题三道(python)
- 阿里巴巴集团2016校园招聘-Python工程师笔试题(附加题+部分答案)
- 吐槽一下测评网的笔试居然只支持 Python 2,害我在 input 上面搞了好久
- 笔试时怎么用Python读取输入行