#利用集合汗唱,直接將列表轉(zhuǎn)化為集合空郊,自動(dòng)去重后轉(zhuǎn)回列表份招。有一個(gè)問(wèn)題,轉(zhuǎn)換為集合的同時(shí)狞甚,數(shù)據(jù)無(wú)序了锁摔。
# li = [11,22,22,33,44,44]
# set = set(li)
# li = list(set)
# print(li)
#第二種運(yùn)用新建字典的方式,去除重復(fù)的鍵
#? list = [11,22,33,22,44,33]
# dic = {}
# list = dic.fromkeys(list).keys()#字典在創(chuàng)建新的字典時(shí)哼审,有重復(fù)key則覆蓋
# print(list)
#
#第三種是用列表的推導(dǎo)
# list = [11,22,33,22,44,33]
# lis = []? ? ? ? ? ? ? ? ? ? ? ? ? #創(chuàng)建一個(gè)新列表
# for i in list:? ? ? ? ? ? ? ? ? ? #循環(huán)list里的每一個(gè)元素
#? ? if? i? not in lis:? ? ? ? ? ? #判斷元素是否存在新列表中谐腰,不存在則添加,存在則跳過(guò)涩盾,以此去重
#? ? ? ? lis.append(i)
# print(lis)
#
#第四種僅僅只是將for循環(huán)變?yōu)閣hile循環(huán)
# list = [11,22,33,22,44,33]
# result_list=[]
# temp_list=list
# i=0
# while i<len(temp_list):
#? ? if temp_list[i] not in result_list:
#? ? ? ? result_list.append(temp_list[i])
#? ? else:
#? ? ? ? i+=1
# print(result_list)