![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
代码训练
@you_123
这个作者很懒,什么都没留下…
展开
-
C++判断文件是否存在
#include <iostream>using namespace std;/// 判断文件是否存在int main(){ string dirPath; dirPath="/home/XXX/.txt"; //你的路径 什么类型的文件都可以 // 进行判断 ifstream txt_file(dirPath); if (!txt_file) { continue; // 如果没有文件,选择跳过或其他的操原创 2022-03-30 20:10:12 · 1287 阅读 · 0 评论 -
python 字典更改
1.字典特性:查找快、无顺序,不可通过索引查找字典元素1.1根据字典的键查找值:方法1:a={'rect':[1,2,3],'string':'this is python','score':95}b=a.get('string') print(b)>>>output:'this is python'方法2:a={'rect':[1,2,3],'string':'this is python','score':95}b=a['string']print(b)&g原创 2020-11-04 23:07:15 · 3245 阅读 · 0 评论 -
图像处理:python3 opencv 给字的周围添加轮廓,随机字符间距
1.实现给文字周围添加轮廓步骤:1.1采用pillow写字:新建一个空白画布,写入文字,可实现随机字符间距#先获得写好文字的图片def text_image_draw(text,font_color,font_path,font_size): #text:文字内容 #font_color:文字颜色 #font_path:字体路径 #font_size:字体大小:int font= ImageFont.truetype(font_path,font_size ) text_w,原创 2020-11-01 23:18:23 · 1057 阅读 · 0 评论 -
python学习笔记 迭代
1.python中的可迭代对象列表、元组、字典、集合、字符串可迭代对象的判断:#通过collections模块的Iterable类型进行判断from collections import Iterableisinstance('slam',Iterable)>>> output:True L=[1,2,3]isinstance(L,Iterable)>>> output:True 2.迭代通过for循环遍历可迭代对象,这种遍历称为迭代(it原创 2020-10-29 20:33:19 · 108 阅读 · 0 评论 -
python学习笔记:函数
1.函数的参数位置参数、默认参数、可变参数、关键字参数、命名关键字参数1.1位置参数:我们常用的、最普通的参数,如想要获得字典a中的键,定义一个函数如下:def get_name(a): name_list=[] #定义一个空列表,用来存放元素 for name in a.keys() : #获得字典中的键 name_list.append(name) #键添加到列表中 print(name_list) return name_listif原创 2020-10-28 22:33:42 · 160 阅读 · 0 评论 -
斐波那契数列python实现,时间/空间复杂度比较
斐波那契数列即1,1,2,...,f(n)=f(n-1) + f(n-2)关于斐波那契数列的实现,最简单的一种,大家都会想到:def fib1(n): if n==0 or n==1: return 1 else: return fib1(n-1) + fib1(n-2)print(fib1(n))但是这种方法的时间复杂度特别高,为O(2^n),一般在计算到n=40以上就很...原创 2019-10-15 20:45:19 · 1454 阅读 · 0 评论 -
python 敏感词过滤2
敏感词保存在txt文件中,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。思路整理:#1.获取敏感词文件,读取文件,将文件放入列表#2.获取用户输入#3.检查用户输入,是否有敏感词语,#4.若是输入中有敏感词语,将敏感词用同等长度的**替换#5.若是输入中没有敏感词,则直接输出file_path='C:/workspace/V...原创 2019-08-13 16:04:00 · 1431 阅读 · 2 评论 -
python 敏感词过滤1 利用cmd模块实现
敏感词文本文件: filtered_words.txt里面的内容如下:北京 程序员 公务员 领导 love ...当用户输入敏感词语:则打印出 Freedom否则打印出 Human RightsSensitive word detection:import cmd#文件存放路径,这里改为你电脑中的文件存放路径filer_path='C:/workspace/VS Co...原创 2019-08-12 17:31:36 · 223 阅读 · 0 评论