""" Demo of various Python language features """

# rely on reuse to avoid duplication
# duplicate code -> more work to maintain
# -> more opportunities for mistakes

L = [1, 2, 3]

sum(L)

# this replaces
total = 0
for n in L:
    total += n


max(L)

# this replaces
largest = L[0]
for n in L:
    if n > largest:
        largest = n


new_L = [2 * n for n in L]

# replaces
new_L = []
for n in L:
    new_L.append(n * 2)


def is_fluffy(word):
    """ Return True iff word is fluffy. """
    for ch in word:
        if ch not in 'fluffy':
            return False
    return True

def shorter_fluffy(word):
    return all([ch in 'fluffy' for ch in word])

# sets
# unordered collection of elements
# no duplicates
# but not paired like a dict

s = {1, 2, 3}
empty_set = set()

L = [1, 2, 1, 3, 1, 5, 6, 6]

# to remove duplicates from L
L = list(set(L))
L.sort()
print(L)

s1 = {1, 2, 3}
s2 = {2, 3, 4}

# union
print(s1 | s2)

# intersection
print(s1 & s2)

# difference
print(s1 - s2)
