Skip to content

Commit 8f70a50

Browse files
authored
Merge pull request #715 from Zeyneepsudee/patch-2
Implement utility functions for list and dict operations - Zeynep Sude
2 parents b60efee + 54e495d commit 8f70a50

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)