From 269e3b3faa8cae2d82e789810e0a085011c84c7b Mon Sep 17 00:00:00 2001 From: ezberaysegul <105494369+ezberaysegul@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:19:01 +0300 Subject: [PATCH] Create sequences_aysegul_ezber.py --- Week03/sequences_aysegul_ezber.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week03/sequences_aysegul_ezber.py diff --git a/Week03/sequences_aysegul_ezber.py b/Week03/sequences_aysegul_ezber.py new file mode 100644 index 00000000..935da40a --- /dev/null +++ b/Week03/sequences_aysegul_ezber.py @@ -0,0 +1,17 @@ +def remove_duplicates(seq: list) -> list: + """ + This function removes duplicates from a list. + """ + return list(dict.fromkeys(seq)) # Using dict.fromkeys to remove duplicates while maintaining order. + +def list_counts(seq: list) -> dict: + """ + This function counts the number of occurrences of each item in a list. + """ + return {item: seq.count(item) for item in set(seq)} # Counts occurrences by iterating over unique items in the list. + +def reverse_dict(d: dict) -> dict: + """ + This function reverses the keys and values of a dictionary. + """ + return {v: k for k, v in d.items()} # Swaps keys and values to reverse the dictionary.