"""
Examples
"""

fruits_lst = ['raspberry', 'mango', 'kiwi']  # ['raspberry', 'mango', 'kiwi']
fruits_tpl = ('raspberry', 'mango', 'kiwi')  # ('raspberry', 'mango', 'kiwi')

# An attempt to append something to a list or a tuple
fruits_lst.append('apple')  # ['raspberry', 'mango', 'kiwi', 'apple']
# fruits_tpl.append('apple') # wont work because a tuple cannot be changed!

# An attempt to modify an element of a list or a tuple
fruits_lst[0] = 'orange'  # ['orange', 'mango', 'kiwi', 'apple']
# fruits_tpl[0] = 'orange'  # wont work either!

fruits_tpl = ('raspberry', 'mango', 'kiwi')
print(len(fruits_tpl))  # number of elements, => 3
print(fruits_tpl[1])  # indexing, => mango
print(fruits_tpl[:2])  # slicing, => ('raspberry', 'mango')
print('mango' in fruits_tpl)  # => True
print('watermellon' in fruits_tpl)  # => False

# Simple packing & unpacking
values = 123, 'crayon', -9.5
print(values)  # (123, 'crayon', -9.5)
print(type(values))  # <class 'tuple'>

a, b, c = values  # a=123, b='crayon', c=-9.5
print(type(a))  # <class 'int'>
print(type(b))  # <class 'str'>
print(type(c))  # <class 'float'>

# To ignore a value, use an underscore
d, _, f = values  # d = 123, f = -9.5
print(d, f)

"""
Packing and unpacking
"""

# Swap two variables
x = 1
y = 99
x, y = y, x
print(x, y)  # 99 1

"""
Lists and enumerate()
"""

fruits_lst = ['raspberry', 'mango', 'kiwi']
enumerate_fruits = enumerate(fruits_lst) # returns an object of enumerate type
print(enumerate_fruits) # unusable value printed

# we need to convert enu merate object to a list to print it
enumerate_fruits_l = list(enumerate_fruits)
print(enumerate_fruits_l)
# [(0, 'raspberry'), (1, 'mango'), (2, 'kiwi')]
# Note that every element of this list is a tuple

fruits_lst = ['raspberry', 'mango', 'kiwi']
for index, fruit in enumerate(fruits_lst):
    print(index, fruit)
# 0 raspberry
# 1 mango
# 2 kiwi
