Returns the unique elements in a given list.
- Create a
set
from the list to discard duplicated values, then return alist
from it.
代码实现
def unique_elements(li):
return list(set(li))
使用样例
unique_elements([1, 2, 2, 3, 4, 3]) # [1, 2, 3, 4]
翻译自:https://www.30secondsofcode.org/python/s/unique-elements