PR3_Skriptsprachen_GruppeD_SL1/s1_a53_6.py

39 lines
1.4 KiB
Python

if __name__ == "__main__":
# Aufgabe 3
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
numbers = numbers[-3:] + numbers[:-3]
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]]
list_to_sort.sort(key=lambda x: x[1]) # in-build-function
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]:
list_to_sort[row], list_to_sort[next_row] = list_to_sort[next_row], list_to_sort[row]
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"))