Skip to content

Commit 5207803

Browse files
authored
Merge pull request #769 from ezberaysegul/patch-15
Create sequences_aysegul_ezber.py
2 parents eb605a9 + 269e3b3 commit 5207803

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Week03/sequences_aysegul_ezber.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
return list(dict.fromkeys(seq)) # Using dict.fromkeys to remove duplicates while maintaining order.
6+
7+
def list_counts(seq: list) -> dict:
8+
"""
9+
This function counts the number of occurrences of each item in a list.
10+
"""
11+
return {item: seq.count(item) for item in set(seq)} # Counts occurrences by iterating over unique items in the list.
12+
13+
def reverse_dict(d: dict) -> dict:
14+
"""
15+
This function reverses the keys and values of a dictionary.
16+
"""
17+
return {v: k for k, v in d.items()} # Swaps keys and values to reverse the dictionary.

0 commit comments

Comments
 (0)