【百度实习录】新人练习
练习1:
import json
try:d1 = json.loads('{"name":"youlin","type":{"name":"seq", "parameter":["1", "2"]}}')d2 = json.loads('{"name":"qixuan02","type":{"name":"seq","parameter":["1", "2"]}}')
except:print 'load json error!!'class Json:def __init__(self):self.json_items = []def append(self, json_item):self.json_items.append(json_item)return selfdef __repr__(self):json_dump = ''for item in self.json_items:json_dump += str(item)return json_dumpclass JsonItem:def __init__(self, reason, expected, actual):self.reason = reasonself.expected = expectedself.actual = actualdef __repr__(self):return 'Reason: {0}\nExpected:{1}\nActual:{2}' \.format(self.reason, _format_value(self.expected), _format_value(self.actual))def _indent(s):return '\n'.join(' ' + line for line in s.splitlines())def _format_value(value):return _indent(json.dumps(value, sort_keys=True, indent=4))def _is_dict_same(expected, actual, keys):for key in expected:if not key in actual:return False, \Json().append(JsonItem('Expected key "{0}" Missing from Actual'.format(key),expected,actual))if not key in keys:# have to change orderare_same_flag, json = _are_same(expected[key], actual[key], keys)if not are_same_flag:return False, \json.append(JsonItem('Different values', expected[key], actual[key]))return True, Json()def _is_list_same(expected, actual, keys):for i in xrange(len(expected)):are_same_flag, json = _are_same(expected[i], actual[i], keys)if not are_same_flag:return False, \json.append(JsonItem('Different values', expected[i], actual[i]))return True, Json()def _are_same(expected, actual, keys):if expected is None:return expected == actual, Json()# Ensure they are of same typeif type(expected) != type(actual):return False, \Json().append(JsonItem('Type Mismatch: Expected Type: {0}, Actual Type: {1}'.format(type(expected), type(actual)),expected,actual))# Compare primitive types immediatelyif type(expected) in (int, str, bool, long, float, unicode):return expected == actual, Json()if len(expected) != len(actual):return False, \Json().append(JsonItem('Length Mismatch: Expected Length: {0}, Actual Length: {1}'.format(len(expected), len(actual)),expected,actual))if isinstance(expected, dict):return _is_dict_same(expected, actual, keys)if isinstance(expected, list):return _is_list_same(expected, actual, keys)return False, Json().append(JsonItem('Unhandled Type: {0}'.format(type(expected)), expected, actual))def json_are_same(a, b, keys=[]):return _are_same(a, b, keys)print json_are_same(a1, a2, [])
练习2:
cat test.txt | awk -F '&luw' 'BEGIN {print "[BEGIN PARSE..]" }
{wordstr=substr($2, 2);split(wordstr, words, "#");channelstr=substr($3, 3);wordstr=substr($2, 2);split(wordstr, words, "#");split($7, temp_arr, "&luctr:");split(temp_arr[2], temp_arr2, "&lumidcpm:");split(temp_arr2[1], luctrs, "#");times[1]=0;times[2]=0;times[3]=0;times[4]=0;times[5]=0;times[6]=0;times[7]=0;times[8]=0;times[9]=0;for (i in words) {channel=substr(channelstr, i, 1);times[channel]++;print "日志行数 "NR" 单词:"words[i]" 通道:"channel" pctr:"luctrs[i];}
}
END {for(i=1; i<10; i++) {print "Channel "i" show "times[i]" times";}
}'
【百度实习录】新人练习相关推荐
- 斩获BAT-offer的阿里大佬的腾讯百度实习经历分享
考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:"乔戈里峰" ...
- 在网易和百度实习之后,我才明白了这些事
之前作者发了几篇关于找实习的文章,讲述了找实习的那些事.其实,比起找实习,实习过程本身更加有趣.先后在网易和百度实习之后,我明白了很多事情,在这里,分享给各位少侠,与君共勉. 壹 在猪场的短暂时光 刚 ...
- 百度实习学弟深夜吐槽:原来大厂是这种生活啊
大家周末好,我是小贺. 这周单休,大家是不是有种身体被掏空的感觉. 小贺我也是下班到家就十点钟了,刚到家,微信上就有人发来几条语音,我一看,原来是学弟. 这小伙子又发生肾么事了? 我定睛一看,学弟一上 ...
- 学姐百度实习面经(轻松拿offer)
本系列历史文章: 学姐,来挑战字节最牛部门 最强阿里巴巴历年经典面试题汇总:C++研发岗 关于我的那些面经--百度后端(附答案) <关于我的那些面经>滴滴Java岗(附答案) 朋友面神策数 ...
- 百度实习测开岗位面试
前言: 面试测开,很荣幸进入百度面试.自己的第一次面试托付给了百度,还是很激动的.HR说测试 :开发 =3:2 然后投了京东.字节.Intel.蔚来.携程,基本没动静. 年前争取找大厂,年后真不容易 ...
- 百度实习笔试题(2012.5.6)
简答题1 一个单词单词字母交换,可得另一个单词,如army->mary,成为兄弟单词.提供一个单词,在字典中找到它的兄弟.描述数据结构和查询过程. 简答题2 线程和进程区别和联系.什么是&quo ...
- 百度实习面经2022-4-24(第一次面试,暂时只面了一场,感觉人无了)
我的学习进度 我走的是JavaEE企业版的开发,目前大三在读,路线也是先学的 c语言.java.HTML+CSS3.Jquery.python等 之后专注于 java 走后端开发路线学了MySQL.J ...
- 2016百度实习编程题:括号序列
不知如何解决 1.感觉贪心或者动态规划,不知道如何解决 2.做过生成合法括号序列的题目,想到用DFS补成合法的括号,然而没有成功
- 寻找兄弟单词(2012.5.6百度实习)
题目:一个单词单词字母交换,可得另一个单词,如army->mary,成为兄弟单词.提供一个单词,在字典中找到它的兄弟.描述数据结构和查询过程. 解法一:使用hash_map和链表 (1)首先定义 ...
最新文章
- BZOJ 3224: Tyvj 1728 普通平衡树 treap
- 计算硼原子的基态能级B---库仑排斥能
- 创建Maven项目时,GroupId和Artifact Id填写
- 微服务API设计的实践与思考总结
- 【机器学习】Kmeans聚类
- 第二章 Python数据类型详解
- 【Leetocde | 24 】152. 乘积最大子序列
- Android实现监测网络状态
- 使用SourceTree
- java反射经典实例 Java Reflection Cookbook
- Django uplodify 多文件同时上传
- PNG in IE - 1 - pngfix.js
- jsp 网页计数器代码
- 计算机数学基础:斜率与截距、导数、权重的关系
- Spring之refresh的12个步骤
- 苹果系统中国日历服务器,简单三步,让 iPhone 自带日历 App 显示国家节假日安排...
- 基于thinkphp校园二手交易网站——毕业设计
- 点击按钮实现页面切换中英文
- Git版本控制管理——版本库管理
- 学习笔记,每日打卡,持续更新