Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Etl #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions practice/etl/etl.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
def transform(legacy_data):
pass
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:
# Convert the letter to lowercase and add it to the new dictionary
new_dict[letter.lower()] = point
return new_dict
Loading