DEV Community

Discussion on: Solving a Job Application Code Challenge

Collapse
 
dimven profile image
Dimitar Venkov • Edited

Here's a py3 version using the builtin dict and iterators:

from operator import itemgetter
long_string = "..."

counter = dict()
for c in iter(long_string):
counter[c] = counter.get(c, 0) + 1

sorted_chars = [k for (k, v) in sorted(counter.items(), key=itemgetter(1), reverse=True)]
word = "".join(sorted_chars[:sorted_chars.index('_')] )

print(word)