![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python基础
心--瘾
个人博客 wyx6.top
展开
-
python defaultdict
defaultdict 可以创建时默认给dict中的类型 举例 from collections import defaultdict a = defaultdict(list) a[1].append("123") a defaultdict(<class 'list'>, {1: ['123']})原创 2021-11-10 14:35:50 · 402 阅读 · 0 评论 -
可以输入 list 输入 正整数的值 这个数是代表每一天的价格 数组的长度代表这一段的时间 一个元素代表一天 从左到右代表时间的顺序
def func(a): ma = 0 for i in range(len(a)): for j in a[i:]: if a[i] - j > ma: ma = a[i] - j return ma if __name__ == '__main__': print(func([55, 58, 57, 50, 100])) 输出 8原创 2021-03-08 18:51:12 · 121 阅读 · 0 评论 -
python获取命令行参数sys、getopt和argparse
import sys print('第一个参数:%s' % sys.argv[0]) if sys.argv[1].startswith('-'): c1 = sys.argv[1][1:] print(c1)原创 2021-02-02 09:39:58 · 213 阅读 · 0 评论 -
获取当前目录下的所有.py结尾的文件
import os import os.path # 获取指定目录及其子目录下的 py 文件路径说明:l 用于存储找到的 py 文件路径 get_py 函数,递归查找并存储 py 文件路径于 l list1 = [] def get_py(path, list1): fileList = os.listdir(path) # 获取path目录下所有文件 for filename in fileList: pathTmp = os.path.join(path, fil原创 2021-02-02 09:31:24 · 1585 阅读 · 1 评论