Skip to content

Commit ae739d6

Browse files
author
Seher Arslanbay
committed
sequences seher arslanbay
1 parent e4fde46 commit ae739d6

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
def remove_duplicates(seq: list) -> list:
3+
"""
4+
removes duplicates from a list.
5+
"""
6+
result = []
7+
8+
for item in seq:
9+
if item not in result:
10+
result.append(item)
11+
12+
return result
13+
14+
15+
def list_counts(seq: list) -> dict:
16+
"""
17+
counts the number of
18+
occurrences of each item in a list.
19+
"""
20+
counts = {}
21+
22+
for item in seq:
23+
if item in counts:
24+
counts[item] += 1
25+
else:
26+
counts[item] = 1
27+
28+
return counts
29+
30+
31+
def reverse_dict(d: dict) -> dict:
32+
"""
33+
reverses the keys
34+
and values of a dictionary
35+
"""
36+
result = {}
37+
38+
for key, value in d.items():
39+
result[value] = key
40+
41+
return result
42+
43+
44+
# Test
45+
if __name__ == "__main__":
46+
print(remove_duplicates([1, 2, 2, 3, 1, 4]))
47+
print(list_counts(["a", "b", "a", "c", "a"]))
48+
print(reverse_dict({"a": 1, "b": 2, "c": 3}))

0 commit comments

Comments
 (0)