Created
August 6, 2019 09:20
-
-
Save tanmaybaranwal/2ff4ddeb52d91bc7e22f375aa29c0baf to your computer and use it in GitHub Desktop.
Get unique smallest string from the list
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
class StringClassifier: | |
def __init__(self, input_data: list): | |
self.input_list = input_data | |
self.input_dict = dict(enumerate(input_data)) | |
self.sorted_dict = dict(enumerate(list(map(lambda x: "".join(sorted(x)), input_data)))) | |
def process(self) -> list: | |
reverse_dict = {} | |
processed_list = [] | |
for key, value in self.sorted_dict.items(): | |
reverse_dict.setdefault(value, set()).add(key) | |
for key, victims in reverse_dict.items(): | |
victim_list = list(filter(lambda x: self.input_list.index(x) in victims, self.input_list)) | |
processed_list.append(min(victim_list)) | |
return processed_list | |
def test_1(): | |
test_data = ['aieou', 'uioae', 'doce', 'aaaa', 'aeiou', 'code', 'edoc', 'aaaaaa', 'aaaa', 'bbb', 'c'] | |
string_classifier = StringClassifier(input_data = test_data) | |
assert ['aeiou', 'code', 'aaaa', 'aaaaaa', 'bbb', 'c'] == string_classifier.process() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment