From 010c241cfd7b95aa40a988e2549645fe340a0488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Tun=C3=A7?= <58087692+Batuhaanccs@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:56:25 +0300 Subject: [PATCH] Implement utility functions for list and dict operations Added functions to remove duplicates, count occurrences, and reverse dictionary. --- Week03/sequences_batuhan_tunc.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week03/sequences_batuhan_tunc.py diff --git a/Week03/sequences_batuhan_tunc.py b/Week03/sequences_batuhan_tunc.py new file mode 100644 index 00000000..d4d60207 --- /dev/null +++ b/Week03/sequences_batuhan_tunc.py @@ -0,0 +1,24 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + return list(dict.fromkeys(seq)) + + +def list_counts(seq: list) -> dict: + """ + This function counts the number of + occurrences of each item in a list. + """ + counts = {} + for item in seq: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys + and values of a dictionary. + """ + return {value: key for key, value in d.items()}