1.python
Python pass是空語句,是爲了保持程序結構的完整性。數組
pass 不作任何事情,通常用作佔位語句。spa
2.刪除一個list裏面的重複元素blog
方法一:是利用map的fromkeys來自動過濾重複值,map是基於hash的,大數組的時候應該會比排序快點吧排序
# *-* coding:utf-8 *-* def distFunc1(): a=[1,2,4,2,4,5,6,5,7,8,9,0] b={} b=b.fromkeys(a) print b #print b.keys() a=list(b.keys()) print a distFunc1()
方法二:是用set(),set是定義集合的,無序,非重複utf-8
>>> a = [1, 3, 2, 2, 1, 5, 5, 3] >>> a = list( set(a) ) >>> print a [1, 2, 3, 5]
方法三:是排序後,倒着掃描,遇到已有的元素刪之hash
1 # *-* coding:utf-8 *-* 2 def distFunc1(): 3 list1 = [1,2,4,2,4,5,6,5,7,8,9,0] 4 if list1: 5 list1.sort() 6 last = list1[-1] 7 for i in range(len(list1)-2, -1, -1): 8 if last == list1[i]: 9 del list1[i] 10 else: 11 last = list1[i] 12 print list1 13 distFunc1()
~ ast