Python习题1

1.请列举 python2 与 python3 的区别,请将下面的 python2 代码转换成
python3。

class Point: def init(self, x, y): self.x = x self.y = y def
str(self): return ‘({}, {})’.format(self.x, self.y) points = [Point(9, 2), Point(1,5), Point(2, 7), Point(3, 8), Point(2, 5)]
sorted_points = sorted( points, lambda (x0, y0), (x1, y1): x0 - x1 if
x0 != x1 else y0 - y1, lambda point: (point.x, point.y))
#预期结果为(1, 5), (2, 5), (2, 7), (3, 8), (9, 2) print ', '.join(map(str, sorted_points)

Python2转python3代码实现:

class Point(): def init(self,x,y):
self._x = x
self._y = y def get_value(self):
return self._x,self._y
points = [Point(9,2),Point(1,5),Point(2,7),Point(3,8),Point(2,5)]
points.sort(key=lambda x:x.get_value()) points_value =
[str(p.get_value()) for p in points] print(",".join(points_value))

  1. 请用 python 写一个正则表达式实现电话号码的提取功能,下面是需要满足条 件:

    a. 匹配(123)-456-7890 和 123-456-7890
    b. 不匹配(123-456-7890 和 123)-456-7890
    

正则表达式提取电话号码:

3.请用 python 写一个正则表达式实现如下内容的匹配,并实现数据的结构化

b6b2af4a-02cb-4a45-819e-c35a74186608 300363 关于公司为全资子公司 Porton
USA,L.L.C.申请融资提供担保的公告 2017-01-25
{
‘uuid’: ‘b6b2af4a-02cb-4a45-819e-c35a74186608’,
‘code’: ‘300363’,
‘title’: ‘关于公司为全资子公司 Porton USA,L.L.C.申请融资提供担保的公告’,
‘date’: ‘2017-01-25’
}

4.描述 python 开发中,协程,线程和进程的区别,请将下面代码改成可以在多
核 CPU 上并行执行的程序。

import os import sys
def dump_file(input_dir):
if not os.path.exists(input_dir):
print('dir {} not exists'.format(input_dir))
return
 path_list = [os.path.join(input_dir, f).strip('\n') for f in
os.listdir(input_dir)]
 file_path_list = filter(lambda file_path: os.path.isfile(file_path),
path_list)
 for file_path in file_path_list:
 print('{}:{} size:{}'.format(os.getpid(), file_path,
os.path.getsize(file_path)))
if __name__ == '__main__':
 if len(sys.argv) > 1:
 dump_file(sys.argv[1])
 else:
dump_file(os.getcwd())

5 请列常用的 python library,并说明其作用基本使用示例

6.请解释什么是 CORS 问题,在什么样的情况下,会遇到这个问题,常用的 python 库里面该怎么解决这个问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值