python中列表的去重复和取重复
>>> test1 = ["aaa","bbb","ccc","aaa","aaa","bbb","ddd","eee"] >>> test2 = [] >>> for i in test1: if i not in test2: test2.append(i) >>> test2 ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] >>> test1[:] ['aaa', 'bbb', 'ccc', 'aaa', 'aaa', 'bbb', 'ddd', 'eee'] >>> test3 = test1[:] >>> test3 ['aaa', 'bbb', 'ccc', 'aaa', 'aaa', 'bbb', 'ddd', 'eee'] >>> for j in test2: if j in test1: test3.remove(j) >>> test1 ['aaa', 'bbb', 'ccc', 'aaa', 'aaa', 'bbb', 'ddd', 'eee'] >>> test3 ['aaa', 'aaa', 'bbb']