Skip to content

Commit 8fd4615

Browse files
authored
Implement utility functions for list and dict operations
Added functions to remove duplicates, count occurrences, and reverse a dictionary.
1 parent f083b29 commit 8fd4615

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎Week03/sequences_kerimcan_dede.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def remove_duplicates(seq: list) -> list:
2+
new_list = []
3+
for i in seq:
4+
if i not in new_list:
5+
new_list.append(i)
6+
return new_list
7+
8+
def list_counts(seq: list) -> dict:
9+
result_dict = dict.fromkeys(seq, 0)
10+
for i in seq:
11+
result_dict[i] = result_dict[i] + 1
12+
return result_dict
13+
14+
def reverse_dict(d: dict) -> dict:
15+
new_dict = {}
16+
for key, value in d.items():
17+
new_dict[value] = key
18+
return new_dict

0 commit comments

Comments
 (0)