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)
l = [1,2,3,2,1] # l = ['你','我','他','她','你'] for i in l: print("the %s has found %s" % (i, l.count(i))) #find duplicate number # print("the %s has found %s" % (i, l.count(i))) #find duplicate string#the method above would repeat count d