Skip to content

Commit 4112cc8

Browse files
week 3 hw sequences
1 parent 414409d commit 4112cc8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 occurrences of each item in a list.
15+
"""
16+
counts = {}
17+
for item in seq:
18+
counts[item] = counts.get(item, 0) + 1
19+
return counts
20+
21+
22+
def reverse_dict(d: dict) -> dict:
23+
"""
24+
This function reverses the keys and values of a dictionary.
25+
"""
26+
return {value: key for key, value in d.items()}

0 commit comments

Comments
 (0)