python中列表元素的去重复
1、方法1
>>> test1 = ["aa","bb","aa","cc","aa","cc","dd","xx","bb"] >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'xx', 'bb'] >>> test2 = [] >>> for i in test1: if i not in test2: test2.append(i) >>> test2 ['aa', 'bb', 'cc', 'dd', 'xx']
2、方法2
>>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'xx', 'bb'] >>> list(set(test1)) ['cc', 'bb', 'aa', 'xx', 'dd']