/
Nik_voz
/
rgpu_python_analysis
Обзор
Документация
Войти
/
Nik_voz
/
rgpu_python_analysis
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
python_analysis/dicts_.py
63 строки
2 KB
«Nick-voz»
feat(dicts): Implement dictionary manipulation functions and add tests
28 мар 2025, 18:35
28 мар 2025, 18:35
1aede32
Код
Авторство
О чём код?
from math import sqrt def dicts_1() -> None: dex_to_hex: dict[int, str] = {} while True: try: new_num = int(input("Insert new value: ")) except KeyboardInterrupt: print() break except ValueError: print("try again") continue if new_num == 0: break dex_to_hex[new_num] = hex(new_num)[2::] __import__("pprint").pprint(dex_to_hex) def dicts_2(en_ru: dict[str, str] | None = None) -> dict[str, str]: en_ru = en_ru or {"bruh": "брух"} return {v: k for k, v in en_ru.items()} def dicts_3( key: str, *, writers: dict[str, list[str]] | None = None ) -> list[str] | str | None: writers = writers or { "Shakespeare": ["Hamlet", "Macbeth", "Othello", "Romeo and Juliet"], "Orwell": ["1984", "Animal Farm", "Homage to Catalonia"], "Hemingway": [ "The Old Man and the Sea", "A Farewell to Arms", "For Whom the Bell Tolls", "The Sun Also Rises", ], "Austen": ["Pride and Prejudice", "Sense and Sensibility", "Emma"], "Tolkien": ["The Lord of the Rings", "The Hobbit", "The Silmarillion"], } for second_name, works in writers.items(): if second_name == key: return works if key in works: return second_name return None def dicts_4(points: list[tuple[int, int]]) -> float: distance: float = 0.0 for i in range(len(points) - 1): dx = points[i][0] - points[i + 1][0] dy = points[i][1] - points[i + 1][1] distance += sqrt(dx**2 + dy**2) return distance if __name__ == "__main__": pass