def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
1. 使用列表项作为键创建字典。这将自动删除任何重复项,因为词典不能有重复的键。
2. 然后,将字典转换回列表。
def my_function(x):
return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)
1. 使用列表项作为键创建字典。这将自动删除任何重复项,因为词典不能有重复的键。
2. 然后,将字典转换回列表。