loading...

re: Solving a Job Application Code Challenge VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hey! Can someone check my python solution? Any hints where/how can the code be better? repl.it/Mnem/0 TY
 

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)

Code of Conduct Report abuse