Skip to content

Instantly share code, notes, and snippets.

@Deepayan137
Created January 16, 2019 11:03
Show Gist options
  • Save Deepayan137/df32f9c43794599223cf1b9b061244e5 to your computer and use it in GitHub Desktop.
Save Deepayan137/df32f9c43794599223cf1b9b061244e5 to your computer and use it in GitHub Desktop.
character majority voting
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