Skip to content

Commit 0d22765

Browse files
Implement utility functions for list and dict operations
Added functions to remove duplicates, count occurrences, and reverse dictionary.
1 parent a8e0eea commit 0d22765

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎Week03/sequences_bugra_ozturk.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
result = []
6+
for item in seq:
7+
if item not in result:
8+
result.append(item)
9+
return result
10+
11+
12+
def list_counts(seq: list) -> dict:
13+
"""
14+
This function counts the number of
15+
occurrences of each item in a list.
16+
"""
17+
counts = {}
18+
for item in seq:
19+
counts[item] = counts.get(item, 0) + 1
20+
return counts
21+
22+
23+
def reverse_dict(d: dict) -> dict:
24+
"""
25+
This function reverses the keys
26+
and values of a dictionary.
27+
"""
28+
return {value: key for key, value in d.items()}

0 commit comments

Comments
 (0)