From b7ef78db06a9321b7de7d3cb1443b53cb04a0b2a Mon Sep 17 00:00:00 2001 From: fengyunli <864542813@qq.com> Date: Mon, 14 Oct 2019 12:21:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=AF=E5=85=B5=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-interview-2019-3.md | 62 +++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/python-interview-2019-3.md b/python-interview-2019-3.md index 66cf49b..a010dba 100644 --- a/python-interview-2019-3.md +++ b/python-interview-2019-3.md @@ -2,7 +2,7 @@ > **答题要求**:将该项目从[地址1]()或[地址2]()**fork**到自己的[GitHub]()或[Gitee](https://gitee.com)仓库并在线填写答案,完成后以发送合并请求(**Pull Request**)的方式提交自己的工作成果,时间120分钟。 -#### 答题人: +#### 答题人:冯兵 #### 题目: @@ -17,7 +17,9 @@ 答案: ``` - + [('a', 1), ('b', 2), ('c', 3), ('d', 4)] + {0: 1, 1: 9, 2: 81} + 6 ``` 2. 下面的Python代码会输出什么。 @@ -48,6 +50,7 @@ 答案: ```Python + 'k1:v1|k2:v2|k3:v3'.split('|') ``` @@ -56,7 +59,15 @@ 答案: ```Python - + def func1(func) + def wrapper(*args, **kwargs) + + result = func(*args, **kwargs) + if result isinstance(result, str): + result = ' '.join([item.capittalize() for item in result]) + return result + return wrapper + ``` 6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。 @@ -78,7 +89,8 @@ 答案: ```Python - + result = sorted(prices, key=lambda x:x.value())[-1].key() + result = [{key: value} for key, value in prices.items() if value > 100] ``` 7. 写一个函数,返回删除列表中重复元素后的新列表,要求保留原有列表元素的顺序。 @@ -86,7 +98,12 @@ 答案: ```Python - + def del_repetion(list1): + new_list = [] + for item in list1: + if item not in new_list: + new_list.append(item) + return new_list ``` 8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。 @@ -94,7 +111,12 @@ 答案: ```Python - + from collecions import defaultdict + def find_str(list1): + new_dict = defualtdict(list) + for item in list1: + new_dict['item'].append(item) + return sorted(new_dict, key=lambda x: len(x.values())).[-1].vulues()[0] ``` 9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 @@ -146,6 +168,30 @@ 答案: ```SQL + 1: + select u.username + from tb_user u + join tb_record r + on u.userid = r.userid + where r.houseid = 1055 + + 2: + select u.username + from tb_user u + join tb_record r + on u.userid = r.userid + where u.usertel != null + group by r.userid + having count(r.userid) > 3 + + 3: + select h.hoseid, h.title + from tb_house h + join tb_record r + on h.houseid = r.houseid + where r.indate = '2018%' and h.area > 50 and r.rented !=0 + group by r.userid + having count(r.usrid)>2 ``` @@ -154,7 +200,7 @@ 答案: ``` - + 用户在浏览器中输入网址,然后解析网址获得ip,客户端与服务端建立连接,django将get请求的资源发送个客户端, ``` 11. 请阐述HTTPS的工作原理以及TCP是如何保证端到端可靠传输的。 @@ -162,7 +208,7 @@ 答案: ``` - + HTTPS是在htttp无状态协议上加了ssh证书,在传输上会先经过ssl层进行加密。TCP在每发送一个请求后,会要求接收方返回一个收到的答复,如果接收方没有答复则重复发送,直到接收方返回收到答复 ``` 12. 在Linux系统中,假设Nginx的访问日志位于`/var/log/nginx/access.log`,该文件的每一行代表一条访问记录,每一行都由若干列(以制表键分隔)构成,其中第1列记录了访问者的IP地址,如下所示。请用一行命令找出最近的100000次访问中,访问频率最高的IP地址及访问次数。 -- Gitee