diff --git a/python-interview-2019-3.md b/python-interview-2019-3.md index 66cf49b285eb715a22bbd1a8cd1e798f52b5097a..47e6eaecdac95aa1e3c6ee73a668944e3a72e494 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,22 +17,24 @@ 答案: ``` - + [('abcd',1),('abcd',2),('abcd',3),('abcd',4),('abcd',5)] + {0:0,2:4,4:16} + 9 ``` 2. 下面的Python代码会输出什么。 ```Python from functools import reduce - + items = [11, 12, 13, 14] print(reduce(int.__add__, map(lambda x: x // 2, filter(lambda x: x ** 2 > 150, items)))) ``` 答案: - ``` - + ```] + [6,7] ``` 3. 对于第2题的代码,如果要实现相同的功能,用生成式应该怎么写? @@ -40,15 +42,20 @@ 答案: ```Python - + [x//2 for x in items if x**2 >150] ``` 4. 用一行代码实现将字符串`k1:v1|k2:v2|k3:v3`处理成字典`{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}`。 - 答案: + 答案 ```Python - + str1 = k1:v1|k2:v2|k3:v3 + b = str1.spilt('|') + dict1 = {} + for b1 in b: + a1 = s1.split(':') + dict1.a1[0]=a1[1] ``` 5. 写一个装饰函数的装饰器,实现如果函数的返回值是字符串类型,就将该字符串每个单词的首字母大写(不用考虑非英文字符串的情况)。 @@ -56,7 +63,12 @@ 答案: ```Python - + def cap_str(func): + def cap2(*args,**kwargs): + if type(args)==str: + result = args.capitalize() + return result + return cap2 ``` 6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。 @@ -78,7 +90,8 @@ 答案: ```Python - + print(max(prices, key=prices.get)) + {key:value for key,value in prices.items() if value>100} ``` 7. 写一个函数,返回删除列表中重复元素后的新列表,要求保留原有列表元素的顺序。 @@ -86,7 +99,13 @@ 答案: ```Python - + def def_list(list1): + list2 = [] + for item in list1: + if item not in list2: + list1.append(item) + list1 = list2 + return list1 ``` 8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。 @@ -94,7 +113,12 @@ 答案: ```Python - + def find_str(list1): + L = len(list1)/2 + for item in lsit1: + if list1.count(item)>L: + return item + return 'None' ``` 9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 @@ -146,23 +170,27 @@ 答案: ```SQL - + select username from tb_user where userid in (select userid from tb_recod where houseid =1055); + select username from tb_user where userid in (select userid where count(userid)>3 from tb_record); + select houseid,title from tb_house left join (select userid from tb_house where area >50 and userid in (select userid where outdate>2018.01.01)); + ``` 10. 请阐述访问一个用Django或Flask开发的Web应用,从用户在浏览器中输入网址回车到浏览器收到Web页面的整个过程中,到底发生了哪些事情,越详细越好。 - 答案: + 答案: - ``` - - ``` + ``` + 输入网址,回车后浏览器会向发送一个该网址的请求给服务器,服务器收到后会根据地址分发到视图下对应的函数 + 做响应,再响应一个页面发送给浏览器 + ``` 11. 请阐述HTTPS的工作原理以及TCP是如何保证端到端可靠传输的。 答案: ``` - + HTTPS在传输过程中会有字节流加密,传输过程也是有序的 ``` 12. 在Linux系统中,假设Nginx的访问日志位于`/var/log/nginx/access.log`,该文件的每一行代表一条访问记录,每一行都由若干列(以制表键分隔)构成,其中第1列记录了访问者的IP地址,如下所示。请用一行命令找出最近的100000次访问中,访问频率最高的IP地址及访问次数。 @@ -181,5 +209,5 @@ 答案: ```Shell - + cat /var/log/nginx/access.log 10000 | max(count(0,14)) ``` \ No newline at end of file