2022-11-05 15:33:32 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# Aufgabe 3
|
|
|
|
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
|
|
for i in range(0, 3):
|
|
|
|
numbers.insert(0, numbers.pop())
|
|
|
|
print(numbers)
|
|
|
|
|
|
|
|
|
|
|
|
# Aufgabe 4
|
|
|
|
def split_chars_and_remove_duplicates(word: str):
|
|
|
|
string_list = list(word)
|
|
|
|
print("Length of the string-list with duplicates: " + str(len(string_list)))
|
|
|
|
string_set = set(string_list)
|
|
|
|
string_list = list(string_set)
|
|
|
|
string_list.sort()
|
|
|
|
print("Length of the string-list without duplicates: " + str(len(string_list)))
|
|
|
|
print(string_list)
|
|
|
|
|
|
|
|
string = "Donaudampfschiffahrtsgesellschaftsstewardess"
|
|
|
|
split_chars_and_remove_duplicates(string)
|
|
|
|
|
|
|
|
# Aufgabe 5
|
|
|
|
list_to_sort = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
|
|
|
|
for row in range(len(list_to_sort)):
|
|
|
|
for next_row in range(row + 1, len(list_to_sort)):
|
|
|
|
if list_to_sort[row][1] > list_to_sort[next_row][1]:
|
2022-11-08 16:11:58 +01:00
|
|
|
list_to_sort[row], list_to_sort[next_row] = list_to_sort[next_row], list_to_sort[row]
|
2022-11-05 15:33:32 +01:00
|
|
|
|
|
|
|
print("The sorted list" + str(list_to_sort))
|
|
|
|
|
|
|
|
# Aufgabe 6
|
|
|
|
def get_the_animal_sound(name_of_animal: str):
|
|
|
|
animal_dictionary = {"Lion": "Growl!", "Dog": "Barks!", "Cat": "Meow!"}
|
|
|
|
return animal_dictionary.get(name_of_animal, "Animal sound not available")
|
|
|
|
|
|
|
|
print(get_the_animal_sound("Dog"))
|