Skip to content

Commit e838687

Browse files
authored
Merge pull request #759 from batyou0ne/patch-4
Implement utility functions for list and dict operations
2 parents 5eebee3 + d53b7c7 commit e838687

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎Week03/sequences_batuhan_keskin.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def remove_duplicates(seq: list) -> list:
2+
"""
3+
This function removes duplicates from a list.
4+
"""
5+
# Sırayı koruyarak tekrarları kaldırmak için dict.fromkeys kullanımı
6+
return list(dict.fromkeys(seq))
7+
8+
9+
def list_counts(seq: list) -> dict:
10+
"""
11+
This function counts the number of 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 and values of a dictionary.
22+
"""
23+
return {v: k for k, v in d.items()}

0 commit comments

Comments
 (0)