From 41c5b7ea6916e29788f3ec7c0ffa20ec19536612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Hakan=20Y=C4=B1ld=C4=B1r=C4=B1m?= Date: Tue, 17 Nov 2026 18:29:55 +0300 Subject: [PATCH] Add functions for removing duplicates and counting items --- Week03/sequences_ahmet_hakan_yildirim.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week03/sequences_ahmet_hakan_yildirim.py diff --git a/Week03/sequences_ahmet_hakan_yildirim.py b/Week03/sequences_ahmet_hakan_yildirim.py new file mode 100644 index 00000000..ea0a67a5 --- /dev/null +++ b/Week03/sequences_ahmet_hakan_yildirim.py @@ -0,0 +1,20 @@ +def remove_duplicates(items): + """Remove duplicates while preserving the first occurrence order.""" + result = [] + for item in items: + if item not in result: + result.append(item) + return result + + +def list_counts(items): + """Return the frequency of each item.""" + counts = {} + for item in items: + counts[item] = counts.get(item, 0) + 1 + return counts + + +def reverse_dict(mapping): + """Swap keys and values; the last key wins for repeated values.""" + return {value: key for key, value in mapping.items()}