Created
January 16, 2019 11:03
-
-
Save Deepayan137/df32f9c43794599223cf1b9b061244e5 to your computer and use it in GitHub Desktop.
character majority voting
This file contains hidden or 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
def CharMajVoting(words): | |
def most_frequent(list_): | |
counter = Counter(list_) | |
return counter.most_common()[0][0] | |
dict_ = defaultdict(list) | |
lengths = [len(word) for word in words] | |
common_length = most_frequent(lengths) | |
for word in words: | |
for i in range(len(word)): | |
dict_[i].append(word[i]) | |
str_='' | |
for i in range(len(dict_)): | |
str_+=most_frequent(dict_[i]) | |
return str_[:common_length] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment