python删除列表中的重复值_如何从 Python 列表中删除重复项
例子解釋
創(chuàng)建一個以 List 作為參數的函數。
創(chuàng)建函數
def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
使用此 List 項作為鍵創(chuàng)建字典。
創(chuàng)建字典
def my_function(x):
return list( dict.fromkeys(x) )
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
將字典轉換為列表:
轉換為列表
def my_function(x):
return list( dict.fromkeys(x) )
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
返回列表:
返回列表
def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
使用列表作為參數來調用該函數:
調用函數
def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
打印結果:
打印結果
def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
總結
以上是生活随笔為你收集整理的python删除列表中的重复值_如何从 Python 列表中删除重复项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 空指针_Python&CT
- 下一篇: stm32l0的停止模式怎么唤醒_「正点