From e4489f52ca1abc083584e79734e1b1d3c323f700 Mon Sep 17 00:00:00 2001 From: duke0425 Date: Mon, 14 Oct 2019 11:26:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=BB=84=E9=BC=8Epython=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E5=A5=97=E8=AF=95=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-interview-2019-3.md | 70 +++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/python-interview-2019-3.md b/python-interview-2019-3.md index 66cf49b..252b479 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,6 +17,10 @@ 答案: ``` + [(a,1),(b,2),(c,3),(d,4)] + {1:item1,3:item9} + 6 + ``` @@ -29,7 +33,7 @@ print(reduce(int.__add__, map(lambda x: x // 2, filter(lambda x: x ** 2 > 150, items)))) ``` - 答案: + 答案:13 ``` @@ -40,7 +44,8 @@ 答案: ```Python - + items = [11, 12, 13, 14] + print(sum([x//2 for x in items if x**2 > 150])) ``` 4. 用一行代码实现将字符串`k1:v1|k2:v2|k3:v3`处理成字典`{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}`。 @@ -48,7 +53,7 @@ 答案: ```Python - + print({i.split(':')[0]:i.split(':')[1] for i in s1.split('|')}) ``` 5. 写一个装饰函数的装饰器,实现如果函数的返回值是字符串类型,就将该字符串每个单词的首字母大写(不用考虑非英文字符串的情况)。 @@ -56,7 +61,13 @@ 答案: ```Python - + def foo1(func1,args,kwargs): + def foo2(args,kwargs): + result = func1() + if type(result) == str: + return result.upper() + return foo2 + ``` 6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。 @@ -78,7 +89,8 @@ 答案: ```Python - + print([key for key,value in prices.items() if value == max(prices.values())]) + print({key:value for key, value in prices.items() if value > 100}) ``` 7. 写一个函数,返回删除列表中重复元素后的新列表,要求保留原有列表元素的顺序。 @@ -86,7 +98,8 @@ 答案: ```Python - + def foo1(list1): + return list(set(list1)) ``` 8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。 @@ -94,7 +107,17 @@ 答案: ```Python - + def foo1(list1): + l1 = len(list1) + flag = l1 // 2 + x1 = {} + for i in list1: + if i not in x1.keys(): + x1[i] = 1 + else: + x1[i] += 1 + return([key for key, value in x1.items() if value > flag][0]) + ``` 9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 @@ -146,7 +169,30 @@ 答案: ```SQL - + 1. + select a.username + from tb_user a + inner join b + on a.userid = b.userid + where a.userid = 1055 + 2. + select username + from tb_user + where userid in + (select userid + from tb_record + group by userid + having count(userid) > 3) + and usertel is not null + 3. + select a.house_id, a.title + from tb_house a + inner join tb_record b + on a.house_id = b.house_id + where indate == 2018 + group by b.house_id + having count(b.house_id) > 2 + and a.area > 50 and a.rented = 0 ``` 10. 请阐述访问一个用Django或Flask开发的Web应用,从用户在浏览器中输入网址回车到浏览器收到Web页面的整个过程中,到底发生了哪些事情,越详细越好。 @@ -154,6 +200,9 @@ 答案: ``` + 网页端通过路由,产生一个http请求到Django服务器 + 客户端通过http的路由调用相应的views事务 + 通过GET返回数据,渲染页面。 ``` @@ -162,6 +211,8 @@ 答案: ``` + HTTPS + TCP ``` @@ -182,4 +233,5 @@ ```Shell + ``` \ No newline at end of file From e8e80332e55ca4ee2f3d1209869d9538945deafb Mon Sep 17 00:00:00 2001 From: duke0425 Date: Mon, 14 Oct 2019 11:37:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86python=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=AC=A1=E8=AF=95=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-interview-2019-3.md | 52 +++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/python-interview-2019-3.md b/python-interview-2019-3.md index 252b479..4a3311c 100644 --- a/python-interview-2019-3.md +++ b/python-interview-2019-3.md @@ -14,12 +14,9 @@ print(len({x for x in 'hello world' if x not in 'abcdefg'})) ``` - 答案: + 答案: [(a,1),(b,2),(c,3),(d,4)] {1:item1,3:item9} 6 ``` - [(a,1),(b,2),(c,3),(d,4)] - {1:item1,3:item9} - 6 ``` @@ -44,13 +41,12 @@ 答案: ```Python - items = [11, 12, 13, 14] - print(sum([x//2 for x in items if x**2 > 150])) + items = [11, 12, 13, 14] + print(sum([x//2 for x in items if x**2 > 150])) ``` - 4. 用一行代码实现将字符串`k1:v1|k2:v2|k3:v3`处理成字典`{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}`。 - 答案: + 答案: ```Python print({i.split(':')[0]:i.split(':')[1] for i in s1.split('|')}) @@ -58,16 +54,15 @@ 5. 写一个装饰函数的装饰器,实现如果函数的返回值是字符串类型,就将该字符串每个单词的首字母大写(不用考虑非英文字符串的情况)。 - 答案: + 答案: ```Python - def foo1(func1,args,kwargs): - def foo2(args,kwargs): - result = func1() - if type(result) == str: - return result.upper() - return foo2 - + def foo1(func1,args,kwargs): + def foo2(args,kwargs): + result = func1() + if type(result) == str: + return result.title() + return foo2 ``` 6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。 @@ -98,8 +93,8 @@ 答案: ```Python - def foo1(list1): - return list(set(list1)) + def foo1(list1): + return list(set(list1)) ``` 8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。 @@ -107,17 +102,16 @@ 答案: ```Python - def foo1(list1): - l1 = len(list1) - flag = l1 // 2 - x1 = {} - for i in list1: - if i not in x1.keys(): - x1[i] = 1 - else: - x1[i] += 1 + def foo1(list1): + l1 = len(list1) + flag = l1 // 2 + x1 = {} + for i in list1: + if i not in x1.keys(): + x1[i] = 1 + else: + x1[i] += 1 return([key for key, value in x1.items() if value > flag][0]) - ``` 9. MySQL关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。 @@ -232,6 +226,6 @@ 答案: ```Shell - + ``` \ No newline at end of file