These exercises are about data types from Session 1 session1.
Exercise 1 - Lists
## [1, 2, 3, 4, 5]
x.## ['a', 'b', 'c', 'd', 'e']
## ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
## ['a', 'b', 'c', 'a', 'b']
## 'c'
## ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b']
Notice how the last value of your list is missing, even though you access it with [-1]. That’s because slicing is exclusive, while indexing is inclusive.
Append the list in variable x. Add the string z.
## ['a', 'b', 'c', 'd', 'e', 'z']
## ['a', 'z']
## ['c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a', 'a']
## ['c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a', 'a', 'c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a', 'a']
## ['c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a']
Notice that .remove() eliminates only the first instance of your specified entry.
Create a list of lists. Use the values 1,2,3,4,5, along with the lists x and y.
## [[1, 2, 3, 4, 5], ['a', 'z'], ['c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a']]
## 'c'
Exercise 2 - Tuples
## (1, 2, 3, 4, 5)
## ('a', 'z')
## ([1, 2, 3, 4, 5], ['a', 'z'], ['c', 'c', 'c', 'c', 'c', 'b', 'b', 'b', 'b', 'b', 'a', 'a', 'a', 'a'])
Exercise 3 - Dictionaries
## {'my_float_list': [1.5, 2.5, 3.5], 'my_integer_list': [4, 5, 6], 'my_strings_tuple': ('a', 'b', 'c')}
## {'GO:0030955': ['PKM', 'ADPRH', 'ATP4A', 'DRG1'], 'GO:0031403': ['IMPA1', 'PDXK'], 'GO:0031402': ['SLC6A4', 'CAPN3', 'TDG', 'ATP1A2']}
## ['PKM', 'ADPRH', 'ATP4A', 'DRG1', 'IMPA1', 'PDXK', 'SLC6A4', 'CAPN3', 'TDG', 'ATP1A2']
## {'GO:0030955': ['PKM', 'ADPRH', 'ATP4A', 'DRG1'], 'GO:0031403': ['IMPA1', 'PDXK'], 'GO:0031402': ['SLC6A4', 'CAPN3', 'TDG', 'ATP1A2'], 'GO:0031420': ['PKM', 'ADPRH', 'ATP4A', 'DRG1', 'IMPA1', 'PDXK', 'SLC6A4', 'CAPN3', 'TDG', 'ATP1A2']}
Hint: Dictionary elements can also be nested dictionaries.
## {'GO:0030955': {'name': 'potassium ion binding', 'genes': ['PKM', 'ADPRH', 'ATP4A', 'DRG1']}, 'GO:0031403': {'name': 'lithium ion binding', 'genes': ['IMPA1', 'PDXK']}, 'GO:0031402': {'name': 'lithium ion binding', 'genes': ['SLC6A4', 'CAPN3', 'TDG', 'ATP1A2']}}
## 'lithium ion binding'
## ['IMPA1', 'PDXK']
Exercise 4 - Sets
## {'PKM', 'GSS', 'MCM10'}