📜  python 计算列表中唯一元素的数量 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:14.064000             🧑  作者: Mango

代码示例1
# Basic syntax:
len(set(my_list))
# By definition, sets only contain unique elements, so when the list
# is converted to a set all duplicates are removed. 

# Example usage:
my_list = ['so', 'so', 'so', 'many', 'duplicated', 'words']
len(set(my_list))
--> 4

# Note, list(set(my_list)) is a useful way to return a list containing
#    only the unique elements in my_list