main
Thore 2023-04-01 02:30:56 +02:00
parent 50e720c81a
commit a319de72cc
3 changed files with 8 additions and 10 deletions

View File

@ -5,6 +5,6 @@ if __name__ == "__main__":
approximate_value = 0
divider = 1
while series_value != round(approximate_value, 6):
approximate_value += 1/divider**2
approximate_value = 1/divider**2
divider += 1
print("The sum equals", series_value, "after adding", divider-1, "reciprocal square numbers.")

View File

@ -3,17 +3,17 @@ class SparseMatrix:
self.__matrix = dict()
def save(self, matrix) -> None:
for row in range(len(matrix)):
for col in range(len(matrix[row])):
if matrix[row][col] != 0:
self.__matrix[(row, col)] = matrix[row][col]
for row, values in enumerate(matrix):
for col, value in enumerate(values):
if value != 0:
self.__matrix[(row, col)] = value
def get(self, row, col) -> int or None:
if self.__matrix[(row, col)]:
return self.__matrix[(row, col)]
def __str__(self) -> str:
return '\n'.join(map(lambda pair: ': '.join(map(str, pair)), self.__matrix.items()))
return '\n'.join(map(lambda pair: ' : '.join(map(str, pair)), self.__matrix.items()))
if __name__ == "__main__":

View File

@ -5,8 +5,7 @@ if __name__ == "__main__":
# 5.4
def remove_duplicates(word: str):
result = "".join(sorted(set(word), key=word.index))
print(word, len(word), "\n", result, len(result))
return "".join(sorted(set(word), key=word.index))
remove_duplicates("Donaudampfschiffahrtsgesellschaftsstewardess")
# 5.5
@ -15,5 +14,4 @@ if __name__ == "__main__":
# 5.6
def get_animal_sound(animal: str) -> str:
animal_dictionary = {"Lion": "Growl", "Dog": "Bark", "Cat": "Meow"}
return animal_dictionary.get(animal, "Not found.")
return {"Lion": "Growl", "Dog": "Bark", "Cat": "Meow"}.get(animal, "Not found.")