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']
标签:test1,test2,aaa,重复,bbb,列表,python,eee,ccc 来源: https://www.cnblogs.com/liujiaxin2018/p/14157264.html