Created
January 16, 2019 11:03
-
-
Save Deepayan137/df32f9c43794599223cf1b9b061244e5 to your computer and use it in GitHub Desktop.
Revisions
-
Deepayan137 created this gist
Jan 16, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ 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]