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 ...
随机推荐
- mui的ajax例子1
mui.ajax()方法,get请求 前端页面: <!DOCTYPE html><html><head> <meta charset="utf-8& ...
- 使用HTML5 canvas做地图(1)基础知识
之前一直想使用HTML5技术全新做一套地图API,可是苦于时间和精力,迟迟未有行动.后来下定决心,利用下班和周末做出一个大体框架出来,现在和网友分享一下自己的整体的一个思路和想法.欢迎大家提出宝贵建议 ...
- mysql 5.7以上安装遇到的问题
参考地址: https://blog.csdn.net/u012278016/article/details/80455439 本人在window上安装mysql 5.7版本以上的mysql,出现很 ...
- python3基础04(requests常见请求)
#!/usr/bin/env python# -*- coding:utf-8 -*- import requestsimport jsonimport reimport urllib3from ur ...
- jQuery_2_常规选择器-简单选择器
JQuery最核心的组成部分就是:选择器引擎.它继承了css的语法,可以对DOM元素的标签名.属性名.状态等进行快速准确的选择. jQuery选择器的写法与CSS 选择器十分类似,只不过他们的功能不同 ...
- LeetCode Remove Duplicates from Sorted Array II 删除整型数组中的重复元素并返回剩下元素个数2
class Solution { public: int removeDuplicates(int A[], int n) { ],*e=&A[]; //s指向“连续数字”的第一个,e往后遍历 ...
- Quartz 配置文件属性
主要配置 Property Name Req'd Type Default Value org.quartz.scheduler.instanceName no string 'QuartzSched ...
- CUDA && GPU中dim3介绍
- SpringBoot学习记录(一)
1. Spring的Java配置方式 Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 1.1. @Configuration 和 @Bean Spring的Java配置方式是 ...
- preprocessing MinMaxScaler
import numpy as npfrom sklearn.preprocessing import MinMaxScalerdataset = np.array([1,2,3,5]).astype ...