<filename>Sets_in_Python.py
# File: Sets_in_Python.py
# Description: Creating and using Sets in Python
# Environment: PyCharm and Anaconda environment
#
# MIT License
# Copyright (c) 2018 <NAME>
# github.com/sichkar-valentyn
#
# Reference to:
# [1] <NAME>. Creating and using Sets in Python // GitHub platform [Electronic resource]. URL: https://github.com/sichkar-valentyn/Sets_in_Python (date of access: XX.XX.XXXX)


# Creating an empty set
s = set()

# Method to add element in the set
s.add('laptop')
print(s)
print()

# Method to remove element from the set
s.remove('laptop')  # If there is no such element in the set it will show mistake
print(s)
print()

# Method to remove element from the set without mistake even if there is no such element
s.discard('laptop')
print(s)
print()

# Method to clear the set
s.clear()
print(s)

# Function to get the number of elements in the set
print(len(s))
print()

# Creating filled set
basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
# Showing the set. Pay attention that repeated values in the set are not shown
print(basket)  # {'banana', 'apple', 'orange', 'pear'} And they can be in any order
print()

# Asking if something is inside set
print('orange' in basket)  # True
print('python' in basket)  # False
print()

# Using loops for the sets. Pay attention that repeated elements in the set are not shown
for x in basket:
    print(x)
print()

<filename>Sets_in_Python.py
# File: Sets_in_Python.py
# Description: Creating and using Sets in Python
# Environment: PyCharm and Anaconda environment
#
# MIT License
# Copyright (c) 2018 <NAME>
# github.com/sichkar-valentyn
#
# Reference to:
# [1] <NAME>. Creating and using Sets in Python // GitHub platform [Electronic resource]. URL: https://github.com/sichkar-valentyn/Sets_in_Python (date of access: XX.XX.XXXX)


# Creating an empty set
s = set()

# Method to add element in the set
s.add('laptop')
print(s)
print()

# Method to remove element from the set
s.remove('laptop')  # If there is no such element in the set it will show mistake
print(s)
print()

# Method to remove element from the set without mistake even if there is no such element
s.discard('laptop')
print(s)
print()

# Method to clear the set
s.clear()
print(s)

# Function to get the number of elements in the set
print(len(s))
print()

# Creating filled set
basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
# Showing the set. Pay attention that repeated values in the set are not shown
print(basket)  # {'banana', 'apple', 'orange', 'pear'} And they can be in any order
print()

# Asking if something is inside set
print('orange' in basket)  # True
print('python' in basket)  # False
print()

# Using loops for the sets. Pay attention that repeated elements in the set are not shown
for x in basket:
    print(x)
print()

# File: Sets_in_Python.py # Description: Creating and using Sets in Python # Environment: PyCharm and Anaconda environment # # MIT License # Copyright (c) 2018 <NAME> # github.com/sichkar-valentyn # # Reference to: # [1] <NAME>. Creating and using Sets in Python // GitHub platform [Electronic resource]. URL: https://github.com/sichkar-valentyn/Sets_in_Python (date of access: XX.XX.XXXX) # Creating an empty set # Method to add element in the set # Method to remove element from the set # If there is no such element in the set it will show mistake # Method to remove element from the set without mistake even if there is no such element # Method to clear the set # Function to get the number of elements in the set # Creating filled set # Showing the set. Pay attention that repeated values in the set are not shown # {'banana', 'apple', 'orange', 'pear'} And they can be in any order # Asking if something is inside set # True # False # Using loops for the sets. Pay attention that repeated elements in the set are not shown