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.

Revisions

  1. Deepayan137 created this gist Jan 16, 2019.
    16 changes: 16 additions & 0 deletions cmv.py
    Original 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]