Here's a py3 version using the builtin dict and iterators:
from operator import itemgetter long_string = "..."
from operator import itemgetter
long_string = "..."
counter = dict() for c in iter(long_string): counter[c] = counter.get(c, 0) + 1
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('_')] )
sorted_chars = [k for (k, v) in sorted(counter.items(), key=itemgetter(1), reverse=True)]
word = "".join(sorted_chars[:sorted_chars.index('_')] )
print(word)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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)