python
MissZhou要努力
不晓日月,不辩兰艾,终日碌碌,安与燕雀相随乎
展开
-
Python多进程写日志ConcurrentLogHandler
文档:https://pypi.org/project/ConcurrentLogHandler/0.9.1/这个类库是通过文件锁实现写日志进程安全的,但是只能通过文件大小控制切割,不能通过时间分割文件。demo:import timeimport logging, logging.configfrom cloghandler import ConcurrentRotatingFileHandlerfrom multiprocessing import Process def原创 2020-12-10 15:26:02 · 1398 阅读 · 1 评论 -
Python try finally执行过程
如果不考虑return,执行顺序是try- 若有异常 exception ,最终finally结束如果有return,先返回finally中的return .感谢老板不杀之恩......原创 2020-10-15 17:08:37 · 506 阅读 · 0 评论 -
linux python根据csv文件信息 复制图片到不同文件夹下
import sysimport csvimport numpyimport pandasimport shutilimport osif __name__ == '__main__': f1 = pandas.read_csv('trainLabels.csv') print f1 record_num = int (f1.describe().ix[0,0]) print...原创 2020-01-09 11:12:30 · 407 阅读 · 0 评论 -
leetcode2 Add Two Numbers【链表模拟大数加法】
给定的链表是倒序的 MDZZ………………我还自己写了半天反转链表,才发现不对…………然后后来又是各种报错,发现自己写麻烦了,总共先定义两个指针,一个作为头,一个往后走就可以了…………AC1.0/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *...原创 2018-03-23 16:21:50 · 262 阅读 · 0 评论 -
leetcode3 Longest Substring Without Repeating Characters【Python刷题】【哈希】
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...原创 2018-06-29 10:02:21 · 196 阅读 · 0 评论 -
leetcode 8. String to Integer (atoi)【Python 正则表达式】
规则好多哦……Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting...原创 2018-07-30 08:20:17 · 310 阅读 · 0 评论 -
leetcode 12. Integer to Roman【Python】模拟
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2018-07-30 09:30:53 · 263 阅读 · 0 评论 -
leetcode 15 3-sum【双指针】
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not cont...原创 2018-08-01 10:31:32 · 313 阅读 · 0 评论 -
leetcode 16 3Sum Closest【双指针 变形】
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...原创 2018-09-05 20:51:25 · 161 阅读 · 0 评论 -
leetcode 18. 4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of tar...原创 2018-09-20 18:28:53 · 139 阅读 · 0 评论 -
leetcode 19. Remove Nth Node From End of List【Python刷题】
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2018-09-27 16:53:00 · 173 阅读 · 0 评论 -
leetcode33. Search in Rotated Sorted Array【旋转数组找指定值 二分】
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found ...原创 2018-10-12 18:42:02 · 156 阅读 · 0 评论 -
leetcode24. Swap Nodes in Pairs【Python刷题】链表交换相邻位置
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only...原创 2018-10-08 20:32:12 · 530 阅读 · 0 评论 -
leetcode 29. Divide Two Integers【二进制】不用除法做整除
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division sho...原创 2018-10-10 17:16:30 · 469 阅读 · 0 评论 -
docker-compose demo1【网页计数器】
感觉只有自己写个demo一行行看才明白啊Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排。Compose 项目由 Python 编写,实现上调用了 Docker 服务提供的 API 来对容器进行管理。因此,只要所操作的平台支持 Docker API,就可以在其上利用 Compose 来进行编排管理。 服务 (service):一个应用...原创 2018-10-23 20:26:18 · 468 阅读 · 0 评论 -
leetcode1 Two sum【基础题】【Python刷题】
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...原创 2018-06-28 09:02:15 · 645 阅读 · 0 评论 -
leetcode11 Container With Most Water【挡板存水,双指针】【Python刷题】
因为是搜单调队列搜到这个题这个就是误导我的博客http://www.cnblogs.com/Phantom01/p/5871977.html想着单调队列想了两天,又综合了单调栈优化dp:hdu1506Largest Rectangle in a Histogram &hdu1505city game dp想了一下是否是单调栈优化,发现了单调队列和单调栈对数组末尾的处理是一样的,区别只是在于...原创 2018-06-27 11:50:16 · 487 阅读 · 0 评论 -
poj2823Sliding Window【单调队列经典题】leetcode239. Sliding Window Maximum【python刷题】
DescriptionAn array of size n ≤ 106 is given to you. There is a sliding window of sizek which is moving from the very left of the array to the very right. You can only see thek numbers in the wi原创 2016-02-23 11:09:11 · 802 阅读 · 0 评论 -
python入门——猜数字游戏
学习资料:www.fishc.com我的第一个程序:print('-------MissZhou的第一个游戏-------------')temp=input('猜猜她心里想的是那个数字')guess=int(temp)if guess==8: print("你怎么猜到了") print("猜到了也没用")else: print("猜错啦 想的是8")pr原创 2016-07-18 17:31:24 · 5532 阅读 · 0 评论 -
python——字符串与序列
字符串python中没有字符的概念==与元组一样,不能直接修改支持拼接版的修改>>> str1='asdf'>>> str1.capitalize()'Asdf'>>> str1'asdf'>>> str1='DSADas'>>> str1.casefold()'dsadas'>>> str1'DSADas'>>> str1.center(40)原创 2016-08-05 18:35:21 · 5982 阅读 · 0 评论 -
python——函数
函数python也分形参实参函数文档(突然发现tab是好用的) def myfirstfun(name):'xxxx'#xxxxxprint(name)>>> myfirstfun(x) SyntaxError: invalid character in identifier>>> myfirstfun('x')x>>> myfirstfun._原创 2016-08-06 16:25:06 · 1306 阅读 · 0 评论 -
pyhton——字典、拷贝、集合、文件
字典>>> dict1={'1':'a','2':'b','3':'c','4':'d'}>>> print(dict1['a'])Traceback (most recent call last): File "", line 1, in print(dict1['a'])KeyError: 'a'>>> print(dict1['1'])a什么原创 2016-08-19 15:41:15 · 980 阅读 · 0 评论 -
python面向对象基础
python虽然简单,依旧具有面向对象的三个特性……file:class Turtle: color='green' weight=10 def climb(self): print("我要一步一步往上爬")shell>>> tt=Turtle()>>> tt.climb<bound method Turtle...原创 2016-08-31 17:31:50 · 694 阅读 · 0 评论 -
python——基本数据类型+常用操作符+循环
python数据类型数值型:整型(python2中有整型和长整型的区别,长整型后面+L python3不做区分 可以做大数运算)浮点 布尔(可认为是整数0,1) T F大写!!!非0的整数值也认为是True科学记数法>>> a=0.0000000000000000025>>> print(a)2.5e-18>>> a=12332454313423>>>原创 2016-07-25 21:41:36 · 980 阅读 · 0 评论 -
python——初级定时器
import time as tclass MyTimer(): def __init__(self): self.unit=['year','month','day','hour','minute','sec'] self.prompt='未开始'; self.lasted=[] self.begin=0原创 2016-07-29 11:45:42 · 509 阅读 · 0 评论 -
python——图形界面的简单实用 easygui
下载easygui的安装包到电脑,进入此路径C:\Python35\python.exe setup.py install这里要注意这个问题:我最开始python是安装在C:\Program Files\Python35下的,但是目录中有空格,就一直说我没有这个命令,汗,所以我把python的安装文件夹直接复制到了c盘下,但是有个问题,安装easygui的时候还是在C:\Program Files原创 2016-08-22 14:21:42 · 4048 阅读 · 2 评论 -
python2.7图像处理相关模块安装使用异常
由于3.5不兼容,昨晚一怒之下卸载之。安装2.7之后,神清气爽。由于要使用numpy,scipy,matplotlib,opencv等一系列模块,主要还是下载exe执行文件用着方便些。vs是个好东西,之前做vtk的时候就用这货编译模块源代码来着,这次在安装模块方面立下汗马功劳如图所示找到python environments之后先安装pip,再用pip安装其他模块,对于安装好的模块在使原创 2017-01-07 19:03:57 · 3582 阅读 · 0 评论 -
python3.4获取网站40x 50x错误并发邮件通知
之前的代码只能获取404……然后服务器挂了……就悲剧了他和 python刷博客访问量其实原理不一样 不是单纯的访问 取状态码 而且我为啥要把脚本放到服务器里跑,真要是断网了还怎么发邮件……电脑里安装了一个python2.7 一个python3.4希望不要打架……还有一个问题:为啥关闭IIS还能访问呢?机制的我关闭了8080端口才解决……一直利用重启的间隙笨原创 2017-05-31 19:15:39 · 1305 阅读 · 0 评论 -
python刷博客访问量
import mechanizeimport cookielibfrom time import ctime,sleepdef run(): print 'start!' for i in range(100): browse() print "run",i,"times ",ctime() sleep(1)def br原创 2017-05-19 15:59:22 · 2068 阅读 · 0 评论 -
#python练习#leetcode 406. Queue Reconstruction by Height【贪心】
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), where h is the height of the person and k is the number of people in front of this原创 2017-06-29 15:25:37 · 1213 阅读 · 0 评论 -
#python练习#leetcode392. Is Subsequence【贪心】
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2017-07-06 13:00:49 · 608 阅读 · 0 评论 -
【tensorflow】基本使用
本系列使用的是tensorflow0.12和极客学院的中文教程有出入import tensorflow as tfstate=tf.Variable(0,name="counter")#使用tensorflow在默认的图中创建节点,这个节点是一个变量one=tf.constant(1)new_value=tf.add(state,one)#对常量与变量进行简单的加法操作update原创 2017-09-17 19:29:16 · 756 阅读 · 0 评论 -
python——列表与元组
列表创建普通列表,见上一个for循环的例子。创建混合类型的列表,就是每个元素可以不是相同类型的数据,也可以列表套列表创建空列表>>> li=[]>>> li[]想列表添加元素append()>>> li.append('misszhou')>>> li['misszhou']>>> li.append('zyj','2013')Traceba原创 2016-07-28 09:58:00 · 351 阅读 · 0 评论