import os import time import sys from xml.dom import minidom, Node from xml.dom.minidom import parse,parseString from stat import * import xml.etree.ElementTree as ET #删除1day前的日志 def DelLog(filepath): if not os.path.isdir(filepath) and not os.path.is
python版本为:2.7 import os,time,shutil,datetime def rmdir(deldir,N): dellist=os.listdir(deldir) deldate= datetime.timedelta(days=N) now = datetime.datetime.now() for i in dellist: os.chdir(deldir) ctime = datetime.datetime.fromtimestamp(os.path.getctime
import os import time import datetime def should_remove(path, pattern, days): if not path.endswith(pattern): return False mtime = os.path.getmtime(path) now = time.time() result = now - mtime > days * 24 * 3600 print "\n>>>>>>>
list = [1,1,3,4,6,3,7] 1. for s in list: if list.count(s) >1: list.remove(s) 2. list2=[] for s in list: if s not in list2: list2.append(s) print list2 3. b = {} b = b.fromkeys(list) print b.keys() 4.set(list)
Python 以指定的概率选取元素 Problem You want to pick an item at random from a list, just about as random.choice does, but you need to pick the various items with different probabilities given in another list, rather than picking any item with equal probability
在使用集合的过程中,我们经常会有遍历集合元素,删除指定的元素的需求,而对于这种需求我们往往使用会犯些小错误,导致程序抛异常或者与预期结果不对,本人很早之前就遇到过这个坑,当时没注意总结,结果前段时间又遇到了这个问题,因此,总结下遍历集合的同时如何删除集合中指定的元素: 1.错误场景复原 public class ListRemoveTest { public static void main(String[] args) { List<User> users = new ArrayList&l