![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
CN-AllenRen
python中级程序员
展开
-
python3中的url编码和解码
python3中的url编码和解码 在用python进行web开发的时候,当url中含有中文,那么传递到后台服务器的会是编码过的url,我们可以用python3把编码后的文本转化成我们可以识别的内容。如下操作: import urllib test_str = "哈哈哈" print(test_str) new = urllib.parse.quote(test_str) print(new) o...原创 2019-02-27 19:52:02 · 2758 阅读 · 0 评论 -
查找最大或最小的 N 个元素
查找最大或最小的 N 个元素 怎样从一个集合中获得最大或者最小的 N 个元素列表?对于熟悉python的人来说,解决这个问题的方法十分简单。 即使用heapq模块。 heapq 模块有两个函数:nlargest() 和 nsmallest() 可以完美解决这个问题。 import heapq import random num = [random.randint(10, 1000) for i ...原创 2019-03-27 12:07:03 · 403 阅读 · 0 评论