Skip to content

Commit

Permalink
improved the code
Browse files Browse the repository at this point in the history
  • Loading branch information
its-ChaTTy committed Apr 22, 2024
1 parent 5ed935f commit 1766db5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions practice/etl/etl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
def transform(old):
new = {}
for point, letters in old.items():
def transform(old_dict):
"""
Transforms the input dictionary by swapping keys with values.
The function iterates over each key-value pair in the input dictionary.
Each value is expected to be a list. For each element in the list, a new
key-value pair is added to the output dictionary, where the key is the
element (converted to lowercase) and the value is the original key from
the input dictionary.
Args:
old_dict (dict): A dictionary to be transformed. Each value should be
a list.
Returns:
dict: The transformed dictionary.
Raises:
TypeError: If a value in the input dictionary is not a list.
"""
new_dict = {}
for point, letters in old_dict.items():
if not isinstance(letters, list):
raise TypeError('Each value in the input dictionary should be a list.')
for letter in letters:
new[letter.lower()] = point
return new
# Convert the letter to lowercase and add it to the new dictionary
new_dict[letter.lower()] = point
return new_dict

0 comments on commit 1766db5

Please sign in to comment.