Skip to content

Commit 92ca64b

Browse files
committed
Add Week3 sequences hw
1 parent 7d8d5e8 commit 92ca64b

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+
return list(dict.fromkeys(seq))
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+
counts = {}
12+
for item in seq:
13+
if item in counts:
14+
counts[item] =counts[item]+1
15+
else:
16+
counts[item]=1
17+
return counts
18+
19+
def reverse_dict(d: dict) -> dict:
20+
"""
21+
This function reverses the keys and values of a dictionary.
22+
"""
23+
result = {}
24+
for k ,v in d.items():
25+
result[v]=k
26+
return result

0 commit comments

Comments
 (0)