"""
Examples
"""
my_set = {1, 2, 3, 'a', 'b', 'c'}
print(type(my_set))  # <class 'set'>

# Creating an empty set
my_set = set()

# Creating a set from a list
my_set = set([1, 2, 2, 3, 'a', 'a', 'b'])
print(my_set)
# {1, 2, 3, 'b', 'a'}

# Finding the set size
print(len(my_set))  # 5

# Figuring out if an element is in the set
print(3 in my_set) 	# True
print('c' in my_set) 	# False

# Adding an element to a set
my_set.add('c')
print(my_set)  # {1, 2, 3, 'b', 'c', 'a'}

# Removing a specific element from a set
my_set.discard('c')
print(my_set)
# discard() does not raise an error if
# the element does not exist, {1, 2, 3, 'b', 'a'}

# Removing an arbitrary element from a set
my_set.pop()
# pop() removes and returns an arbitrary element from the set.
# If the set is empty, it raises an error KeyError: 'pop from an empty set'
# {2, 3, 'b', 'a'}

"""
Intersection
"""
pirate = set('jacksparrow')  # {'p', 'o', 'k', 'r', 'a', 'w', 's', 'j', 'c'}
king_in_the_north = set('johnsnow')  # {'o', 'h', 'w', 's', 'j', 'n'}

# Intersection = elements present in both sets
my_intersection = pirate & king_in_the_north
print(my_intersection)
# {'w','s','j','o'}
# 4 elements

"""
Union
"""

pirate = set('jacksparrow')  # {'p', 'o', 'k', 'r', 'a', 'w', 's', 'j', 'c'}
king_in_the_north = set('johnsnow')  # {'o', 'h', 'w', 's', 'j', 'n'}

# Union, elements present in one set or the other
my_union = pirate | king_in_the_north
print(my_union)
# {'r', 'j', 'p', 's', 'w',
# 'n', 'c', 'o', 'k', 'a', 'h'}
# 11 elements, arbitrary ordering

"""
Difference
"""

pirate = set('jacksparrow')  # {'p', 'o', 'k', 'r', 'a', 'w', 's', 'j', 'c'}
king_in_the_north = set('johnsnow')  # {'o', 'h', 'w', 's', 'j', 'n'}

# Difference = set – intersection
my_difference = pirate - king_in_the_north
print(my_difference)
# {'k', 'r', 'p', 'c', 'a'}
# 5 elements

"""
Symmetric Difference
"""

# reminder
# union: {'r','j','p','s','w','n','c','o','k','a','h'}
# intersection: {'w','s','j','o'}

# Symmetric difference = union – intersection
my_sym_difference = pirate ^ king_in_the_north
print(my_sym_difference)
# {'k', 'r', 'a', 'p', 'c', 'n', 'h'}
# 7 elements

"""
Example: Removal of Duplicates from a List
"""


def remove_duplicates(input_list):
    return list(set(input_list))


l = list('johnsnow')
print(l)
# ['j', 'o', 'h', 'n', 's', 'n', 'o', 'w']

l_without_repetitions = remove_duplicates(l)
print(sorted(l_without_repetitions))
# ['h', 'j', 'n', 'o', 's', 'w']
