mytuple = ("sausage", "eggs", "bacon")
type(mytuple)
mylist = list(mytuple)

"""
Explanation: Exercises
Tuples and lists

Create a tuple called mytuple, with the following strings: "sausage", "eggs" and "bacon"
check it's type using ``type()```
coerce it to a list using list() and assign to mylist
End of explanation
"""


mylist.append("spam")
mytuple.append("spam")

"""
Explanation: Attempt to append the string "spam" 
to mylist and mytuple using append.
End of explanation
"""


mylist.sort()
print(mylist[0])
del mylist[-1]
print(mylist)

"""
Explanation: List objects have a sort()
function, use that for sorting the list alphabetically (e.g.
mylist.sort() ). What is now the first item of the list?
Next, remove the first item from the list, investigate the contents and remove then last item from the list.
End of explanation
"""


numbers = list(range(50, 0, -2))

"""
Explanation: Slicing
Using range() create a list that has the numbers from 50 to 0 with a step of -2. Note that in Python 3 range() returns an iterator (we'll discuss iterators more later on), list(range(args)) returns an actual list.
End of explanation
"""


print(numbers[-4])
print(numbers[10:14])
print(numbers[:5])

"""
Explanation: Using slicing syntax, select
* the last 4 items from the list
* the items from index 10 to index 13
* the first 5 items from the list
End of explanation
"""


print(numbers[::3])
print(numbers[1::2])

"""
Explanation: Read up on the stride syntax . Then using it select 
* every third value in the list
* the values with an odd-numbered index in the list
End of explanation
"""


coordinates = [[0.1, 4.5], [-1.2, 3], [2.2, -5], [3.4, 1.6]]

"""
Explanation: Multidimensional lists
Create a two dimensional list of (x,y) value pairs, i.e.
arbitrary long list whose elements are two element lists.
Are you able to use slicing for extracting only the y values? (Answer is no, but try it in any case)
End of explanation
"""


fruits = {'banana' : 5, 'strawberry' : 7, 'pineapple' : 3}
print(fruits)
fruits['orange'] = 4.5
print(fruits)
del fruits['banana']
print(fruits)

"""
Explanation: Dictionaries
Create a dictionary whose keys are the fruits “pineapple”, “strawberry”, and “banana”. As values use numbers
representing e.g. prices. 
Add “orange” to the dictionary and then remove “banana” from the dictionary. Investigate the contents of dictionary and pay attention to the order of key-value pairs.
End of explanation
"""


apple = {'color' : 'green', 'weight' : 120}
orange = {'color' : 'orange', 'weight' : 110}
fruits = {'apple' : apple, 'orange' : orange}
print(fruits)
fruits['apple']['color'] = 'red'
print(fruits)

"""
Explanation: Bonus exercises
Create a new “fruits” dictionary where the values are also
dictionaries containing key-value pairs for color and weight,
e.g. 
fruits['apple'] = {'color':'green', 'weight': 120}
Change the color of apple from green to red
End of explanation
"""


grades = {}
grades['Jussi'] = []
grades['Jyry'] = []
print(grades)
grades['Jussi'].append(2)
grades['Jyry'].append(5)
print(grades)
grades['Jussi'].append(3)
grades['Jyry'].append(4)
print(grades)

"""
Explanation: It is often useful idiom to create empty lists or dictionaries
and add contents little by little.
Create first an empty dictionary for a mid-term grades of
students. Then, add a key-value pairs where the keys are
student names and the values are empty lists. 
Finally, add values to the lists and investigate the contents of the
dictionary.
End of explanation
"""


