Skip to content

Commit 99e3510

Browse files
authored
Add functions to manipulate lists and dictionaries
1 parent c791962 commit 99e3510

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def remove_duplicates(seq: list) -> list:
2+
return list(dict.fromkeys(seq))
3+
4+
def list_counts(seq: list) -> dict:
5+
counts = {}
6+
for item in seq:
7+
counts[item] = counts.get(item, 0) + 1
8+
return counts
9+
10+
def reverse_dict(d: dict) -> dict:
11+
return {value: key for key, value in d.items()}
12+
13+
sample_list = [1, 2, 2, 3, 4, 4, 5]
14+
sample_dict = {'a': 1, 'b': 2, 'c': 3}
15+
16+
print("Original list:", sample_list)
17+
print("List after removing duplicates:", remove_duplicates(sample_list))
18+
print("Counts of each element in the list:", list_counts(sample_list))
19+
print("Original dictionary:", sample_dict)
20+
print("Reversed dictionary:", reverse_dict(sample_dict))

0 commit comments

Comments
 (0)