#!/usr/bin/python #Filename: readlinepy.py import sys,re urldir=r"C:\python27\a.txt" distone={} numTen=[] #先文档变成一个字典 f=open(urldir,'r') for line in f.readlines(): #去掉非字符的符号 line = re.sub('\W'," ",line) lineone=line.split() for keyone i
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. 这里题目要求找出出现次数超过n/2的元素. 可以先排序,
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2524 Accepted Submission(s): 888 Problem Description Marica is very angry with Mirko because he found a new gi
介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -*- import re,time def mail_log(file_path): global count log=open(file_path,'r') C=r'\.'.join([r'\d{1,3}']*4) find=re.compile(C) count={} for i in log: