re.match与re.search的区别 re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None:而re.search匹配整个字符串,直到找到一个匹配. 实例 #!/usr/bin/python import re line = "Cats are smarter than dogs"; matchObj = re.match( r'dogs', line, re.M|re.I) if matchObj: print "match
1.使用set集合,虽然去除掉重复元素,但是顺序改变了 耗时约4.0*10^-5 s A = ['a','b','X','a','b','G'] B = list(set(A)) print(A)['a', 'b', 'X', 'a', 'b', 'G'] print(B)['a', 'X', 'b', 'G'] 2.不改变顺序的去重方法 耗时约4.5*10^-5 s A = ['a','b','X','a','b','G'] B = sorted(set(A),key=A.index) pri
class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ flag = 0 lis = [] for i in range(nums.count(target)): sec = flag flag = nums[flag:].index(target)