Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 59 additions & 13 deletions python-interview-2019-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> **答题要求**:将该项目从[地址1](<https://github.com/jackfrued/python-interview-2019>)或[地址2](<https://gitee.com/jackfrued/python-interview-2019>)**fork**到自己的[GitHub](<https://github.com/>)或[Gitee](https://gitee.com)仓库并在线填写答案,完成后以发送合并请求(**Pull Request**)的方式提交自己的工作成果,时间120分钟。

#### 答题人:
#### 答题人:黄鼎

#### 题目:

Expand All @@ -14,9 +14,10 @@
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

```


```

Expand All @@ -29,7 +30,7 @@
print(reduce(int.__add__, map(lambda x: x // 2, filter(lambda x: x ** 2 > 150, items))))
```

答案:
答案:13

```

Expand All @@ -40,23 +41,28 @@
答案:

```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'}`。

答案:
答案:

```Python

print({i.split(':')[0]:i.split(':')[1] for i in s1.split('|')})
```

5. 写一个装饰函数的装饰器,实现如果函数的返回值是字符串类型,就将该字符串每个单词的首字母大写(不用考虑非英文字符串的情况)。

答案:
答案:

```Python

def foo1(func1,args,kwargs):
def foo2(args,kwargs):
result = func1()
if type(result) == str:
return result.title()
return foo2
```

6. 下面的字典中保存了某些公司股票的代码(字典中的键)及价格(字典中的值,以美元为单位),用一行代码从中找出价格最高的股票对应的股票代码,再用一行代码将股价高于100美元的股票创建成一个新的字典。
Expand All @@ -78,23 +84,34 @@
答案:

```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. 写一个函数,返回删除列表中重复元素后的新列表,要求保留原有列表元素的顺序。

答案:

```Python

def foo1(list1):
return list(set(list1))
```

8. 写一个函数,该函数的参数是一个保存字符串的列表,列表中某个字符串出现次数占列表元素总数的半数以上,找出并返回这个字符串。

答案:

```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关系型数据库中有三张表分别表示用户、房源和租房记录,表结构如下所示。
Expand Down Expand Up @@ -146,14 +163,40 @@
答案:

```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页面的整个过程中,到底发生了哪些事情,越详细越好。

答案:

```
网页端通过路由,产生一个http请求到Django服务器
客户端通过http的路由调用相应的views事务
通过GET返回数据,渲染页面。

```

Expand All @@ -162,6 +205,8 @@
答案:

```
HTTPS
TCP

```

Expand All @@ -181,5 +226,6 @@
答案:

```Shell


```