forked from PyAr/exercism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ed935f
commit 1766db5
Showing
1 changed file
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |