A set stores distinct elements without treating their order as significant. In Python, it is useful when a program needs a unique collection, such as the words gathered from several input files. section 20.1.3 section 20.3.4
Collecting unique words
Create an empty set, clean each input word, and add it with words.add(word). Repeated words collapse into one element; Python displays the result with curly braces. section 20.3.4 section 20.1.3
words = set()
for fh in args.file: #1
for line in fh: #2
for word in filter(word_len, map(clean, line.lower().split())): #3
words.add(word.title()) #4
A compact implementation shows how files, lines, cleaning, length filtering, title casing, and set insertion build a unique word collection. section 20.3.4
Sets also support operations beyond deduplication. Set intersection finds values shared by two sets, such as the numbers 5 through 9 in overlapping ranges. section 20.1.3














