lst = [1, 2, 2, 3, 4, 4, 5]
unique_set = set(lst)
print(unique_set) # 输出:{1, 2, 3, 4, 5}
set1 = {1, 2, 3, 4, 5}
set2 = {3, 4, 5, 6, 7}
union_set = set1.union(set2)
intersection_set = set1.intersection(set2)
difference_set = set1.difference(set2)
print(union_set) # 输出:{1, 2, 3, 4, 5, 6, 7}
print(intersection_set) # 输出:{3, 4, 5}
print(difference_set) # 输出:{1, 2}
s = {1, 2, 3, 4, 5}
if 3 in s:
print("3存在于集合中")
lst = [1, 2, 2, 3, 4, 4, 5]
if len(lst) == len(set(lst)):
print("列表中没有重复元素")
else:
print("列表中存在重复元素")
lst = [1, 2, 2, 3, 4, 4, 5]
unique_elements_count = len({x for x in lst})
print(unique_elements_count) # 输出:5