[Python] Create Unique Unordered Collections in Python with Set

A set is an unordered collection with no duplicate items in Python. In this lesson, you will learn how to create them, and perform basic operations to determine members in the set and compare the values from different sets.

# create a set
animals = {'dog', 'cat', 'bird'}

# create an empty set
foo = set()

# add value to set
foo.add('bar')

# remove value from set
foo.remove('bar')

fish = {'wheel'}

# merge set
t = animals.union(fish) 
原文地址:https://www.cnblogs.com/Answer1215/p/8020426.html