![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
virusos
混子king
展开
-
pip install 常用参数
-r, --requirement <file>Install from the given requirements file. This option can be used multiple times.-e, --editable <path/url>Install a project in editable mode (i.e. setuptools “develop mode”) from a local project path or a VCS url.-原创 2021-12-22 15:33:40 · 1077 阅读 · 2 评论 -
python setup.py的基本用法
import setuptools# 最主要的方法就是这个⬇️,给它加上不同的参数setuptools.setup(**setup_args)原创 2021-12-15 15:11:16 · 2589 阅读 · 0 评论 -
mac安装pycurl的坑
问题描述:使用tornado时,要用proxy,一直不通,但是也没报错。response = await AsyncHTTPClient().fetch( HTTPRequest( url="", validate_cert=False, proxy_host=PROXY_HOST, proxy_port=PROXY_PORT,原创 2021-11-04 13:51:47 · 314 阅读 · 0 评论 -
tornado中finish和write区别
转载的简介finish和write都可以将后端的数据传输到前端。他们有啥差别嘞。该项目的github地址: tornado_learning.git例子代码apps/hello/write_finish_handler.pyfrom tornado_learning.handler import BaseHandlerimport timeclass Write_Finish_Handler(BaseHandler): def get(self): self.wr原创 2021-10-29 16:15:50 · 374 阅读 · 0 评论 -
二分查找、快速排序、冒泡排序、选择排序
class Solution: def search(self, nums: List[int], target: int) -> int: l = 0 r = len(nums) - 1 while l <= r: mid = l + (r - l) // 2 if nums[mid] == target: return mid eli原创 2021-05-26 23:17:00 · 63 阅读 · 0 评论 -
142. 环形链表 II
题目:给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。思路:哈希表,把遍历过的节点加入表中快慢指针设快指针为f,慢指针为s,非环形链表的长度为a(不包括环形链表的第一个节点),环形链表总长度为b(包括环形链表的第一个节点)。f每次走2,s每次走1.则f和s第一次相遇时,有:f=2s(因为f的速度为s两倍)f=a+ib(在环里绕了i圈)s=a+jb(在环里绕了j圈)第二、三式子合一下变成f=s+(j-i)b,这里j-i等于多少不关心,可以用n代替,也就是原创 2021-05-08 20:38:12 · 84 阅读 · 1 评论 -
6. Z 字形变换
思路:遍历字符串,用一个列表去模拟“变换后的每一行”,把遍历到的字符填入列表中它应在的行数。定义一个flag,用于记录当前填入行的方向是向下还是向上。在遇到最后一行或第一行的时候,反转flag的值。class Solution: def convert(self, s: str, numRows: int) -> str: if numRows == 1: return s line = ["" for _ in range(numRo原创 2021-05-08 16:29:24 · 53 阅读 · 0 评论 -
python知识点
迭代器是一个可以遍历的对象,包含了一组元素,实现了__iter__()和__next__()方法。当执行next()操作时,返回其中一个元素。当所有元素都被返回后,再执行next()报异常—StopIteration生成器是使用了yield关键字的函数,这个函数也可以称作是一个迭代器。生成器是一种特殊的迭代器,生成器自动实现了“迭代器协议”(即__iter__和__next__方法),不需要再手动实现这两个方法。inner引用outer作用域的变量(即x。原创 2021-04-18 11:43:57 · 418 阅读 · 4 评论 -
python的copy、deepcopy
参考牛客网这个回答:https://www.nowcoder.com/test/question/done?tid=40650380&qid=144534#summary写的很清楚import copya = [1, 2, 3, 4, ['a', 'b']] b = a # 引用,除非直接给a重新赋值,否则a变则b变,b变则a变c = copy.copy(a) # 浅复制,只会拷贝父对象, 不会拷贝父对象中的子对象,所以若a的子对象变则c 变,但是父对象变c不会变d = co原创 2021-01-20 21:42:36 · 57 阅读 · 0 评论 -
【力扣】350. 两个数组的交集 II
350. 两个数组的交集 II注意,题中有个进阶要求:如果 nums2 的元素存储在磁盘上,内存是有限的,并且你不能一次加载所有的元素到内存中,你该怎么办?这时推荐哈希表解法。因为无法一次加载nums2的元素到内存中的话,无法对nums2进行排序;而哈希表算法中只对nums2进行查询操作。解法一:先排序,然后用指针class Solution(object): def intersect(self, nums1, nums2): """ 先排序,后指针原创 2021-01-01 21:28:08 · 213 阅读 · 0 评论 -
【力扣】136. 只出现一次的数字
136. 只出现一次的数字class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int 位运算 -- 异或 """ single = 0 for i in nums: single = single ^ i return sin原创 2020-12-30 22:29:24 · 70 阅读 · 0 评论 -
【力扣】20. 有效的括号
20. 有效的括号这是我刷了几天题以来第一道标着“简单”同时我也觉得还算简单的题,蛋疼class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] # 抄别人的,本来我是用if一个个判断的,好傻 mapping = { ')': '(',原创 2020-12-26 13:01:10 · 87 阅读 · 0 评论 -
【力扣】14. 最长公共前缀
14. 最长公共前缀class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ length = len(strs) if length == 0: return "" prefix = strs[0]原创 2020-12-26 12:22:05 · 93 阅读 · 0 评论 -
13. 罗马数字转整数
题目13. 罗马数字转整数我的答案(比较弱智2333)class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ table = { 'I': 1, 'V': 5, 'X': 10, 'L': 50,原创 2020-12-22 21:40:54 · 71 阅读 · 2 评论 -
【力扣】746. 使用最小花费爬楼梯
题目746. 使用最小花费爬楼梯我的答案(虽然题目要求不新创矩阵但是其他解法我还不会哈)class Solution(object): def minCostClimbingStairs(self, cost): """ :type cost: List[int] :rtype: int """ n = len(cost) minCost = [0] * n minCost[1] =原创 2020-12-22 21:13:33 · 72 阅读 · 0 评论 -
【力扣】48. 旋转图像
题目48. 旋转图像我的答案(虽然题目要求不新创矩阵但是其他解法我还不会哈)class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ n = len(matrix原创 2020-12-19 22:33:01 · 115 阅读 · 1 评论 -
【力扣】389.找不同
题目389. 找不同我的答案(不是最精简的)class Solution(object): def findTheDifference(self, s, t): """ :type s: str :type t: str :rtype: str """ list_s = list(s) for i in t: try: list原创 2020-12-18 20:05:06 · 130 阅读 · 1 评论 -
【力扣】49. 字母异位词分组
题目49. 字母异位词分组我的答案(不是最精简的)class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ table = dict() for current_str in strs: if ''.join(sort原创 2020-12-17 19:55:44 · 104 阅读 · 0 评论 -
Python做算法题常用内置函数
set() 集合dict() 定义字典列表list求长度:len(list_1)添加元素:list_1.append()循环for i in range(0, len(list_1)):原创 2020-12-17 19:43:53 · 305 阅读 · 0 评论 -
Python-sorted与sort,以及模拟内置函数sorted()
比较python中sorted与sort的区别,以及模拟内置函数sorted()原创 2016-05-01 16:08:51 · 11130 阅读 · 4 评论 -
python-模拟math.pi
编写循环控制代码用下面公式逼近圆周率(精确到小数点后15位),并且和math.pi的值做比较。原创 2016-05-01 20:48:30 · 2535 阅读 · 0 评论 -
python基础-将python作为计算器
(1)求下式计算结果,并且计算该结果各位数字之和: (2)判断下式计算结果十位数字的值原创 2016-05-01 20:28:26 · 398 阅读 · 0 评论