Careercup - Microsoft面试题 - 5485521224597504
2014-05-12 06:19
原题:
Given an input list of lists.. flatten the list. For e.g.
{{,}, {}, {,}} ... Output should be {, , , , }
题目:给定一个二维数组,把它展开成一维数组。
解法:之前做了一道题,把维度不定的数组展开成一维数组。这题也能用那题的代码来解决。
代码:
# http://www.careercup.com/question?id=5485521224597504
#!/usr/bin/python def flatten(container, new_container):
for element in container:
if isinstance(element, list) or isinstance(element, tuple) or isinstance(element, set):
flatten(element, new_container)
else:
new_container.append(element)
pass if __name__ == '__main__':
a = [1, 2.3, [3, [1, 222]], (4, 111, 0), "string", set([1, "hello", 3.33])]
res = []
flatten(a, res)
print(res)
pass
Careercup - Microsoft面试题 - 5485521224597504的更多相关文章
- Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...
- Careercup - Microsoft面试题 - 6366101810184192
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- Careercup - Microsoft面试题 - 5700293077499904
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...
- Careercup - Microsoft面试题 - 5204967652589568
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...
- Careercup - Microsoft面试题 - 5175246478901248
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...
- Careercup - Microsoft面试题 - 5718181884723200
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...
- Careercup - Microsoft面试题 - 5173689888800768
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
随机推荐
- 命令行启动mysql服务
在<计算机网络>课程中曾学过net命令,可以用于启动后台服务.在mysql中,net命令用于启动后台服务器进程mysqld,即后台服务. 不过,如果在普通用户模式下net start my ...
- C#之razor
学习的文章在这里:http://www.cnblogs.com/yang_sy/archive/2013/08/26/ASPNET_MVC_RAZOR_ENGINE.html 1.视图开始文件_Vie ...
- Python http
# import httplib # http_client = None # http_client = httplib.HTTPConnection('localhost', 8080, time ...
- IOS 自定义Layer(图层)
方式1: @interface NJViewController () @end @implementation NJViewController - (void)viewDidLoad { [sup ...
- 关于profile集合
profile集合是mongodb的慢操作日志 > db.getProfilingStatus() { , , } 可以通过getProfilingStatus来查看当前profile设置 pr ...
- 【转】iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
iOS上面对键盘的处理很不人性化,所以这些功能都需要自己来实现, 首先是点击return和屏幕隐藏键盘 这个首先引用双子座的博客 http://my.oschina.net/plumsoft/blog ...
- python_64_装饰器7
# home密码认证是本地文件认证,bbs密码认证是远程ldat认证 import time user, passwd = 'qi', '123' def auth(auth_type): print ...
- DongDong跳一跳
题目连接:https://ac.nowcoder.com/acm/contest/904/C 题意很好理解,思路想歪了,本来一道很简单的题,写了好久没写出来. 思路就是找每一个高度最大值的时候就是找“ ...
- 输入hostname -f提示:hostname: Unknown host
解决方法:将/etc/hosts文件中的内容添加如下所示 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdo ...
- .NET AJAX实例
引用地址:http://blog.csdn.net/qianjiu/article/details/7524228 5.2 Ajax基础http://book.csdn.net/bookfiles/6 ...