Created
August 27, 2017 16:11
-
-
Save erikbern/4809c6f391bdcb63fb503e3ebcd52ed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from num2words import num2words | |
from matplotlib import pyplot | |
lang = 'de' | |
words = [num2words(i, lang=lang) for i in range(1000000)] | |
fig = pyplot.figure() | |
ax = fig.add_subplot(111) | |
ax.semilogx([len(word) for word in words], color='green') | |
for p in range(1, 6): | |
lo, hi = 10**p, 10**(p+1) | |
if hi > len(words): | |
break | |
x_max = max(range(lo, hi), key=lambda x: len(words[x])) | |
kwargs = dict(horizontalalignment='right', arrowprops=dict(shrink=0.05, width=2.0, headwidth=5.0, headlength=2.0, facecolor='black')) | |
ax.annotate('%d: "%s" (%d)' % (len(words[x_max]), words[x_max], x_max), xy=(x_max, len(words[x_max])), xytext=(x_max, len(words[x_max])+10), **kwargs) | |
pyplot.xlim([0, len(words)]) | |
pyplot.ylim([0, 100]) | |
pyplot.title('Number of letters of the German word for each number') | |
pyplot.tight_layout() | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment