Homework: Data Structures, control flow, logic¶
In [ ]:
test_string = "This is my test STRING."
final_string = test_string[::3].lower()
print(final_string)
tssye rg
Problem 2:¶
In [ ]:
species_dict = {
'Rattus': 'norvegicus',
'Taeniopygia': 'guttata',
'Taeniopygia': 'castanotis',
'Drosophila': 'melanogaster',
'Macaca': 'mulatta',
'Macaca': 'nemestrina',
}
print(species_dict)
{'Rattus': 'norvegicus', 'Taeniopygia': 'castanotis', 'Drosophila': 'melanogaster', 'Macaca': 'nemestrina'}
Problem 3:¶
In [ ]:
this_tuple = (
['foo', 1, 0, 'bar', 2.78, True],
{'a': 1, 'b': 2, 'c': 3},
'a simple string'
)
list(zip(*this_tuple))
Out[ ]:
[('foo', 'a', 'a'), (1, 'b', ' '), (0, 'c', 's')]
Control flow, iteration, logic¶
In [ ]:
initial_string = "it was the best of times, it was the worst of times"
replacement_dict = {
'a': '\u03b1',
'e': '\u03b5',
'i': '\u03b9',
'o': '\u03bf',
'u': '\u03c5'
}
output_list = []
for letter in initial_string:
if letter in replacement_dict:
output_list.append(replacement_dict[letter])
else:
output_list.append(letter)
output_string = ''.join(output_list)
print(output_string)
ιt wαs thε bεst οf tιmεs, ιt wαs thε wοrst οf tιmεs