3 ms·
Was this article really just pointing out that functions can be put into submodules, imported into other modules, and used by other fucntions? I was hoping for
by eesmith 8y ago
Was this article really just pointing out that functions can be put into submodules, imported into other modules, and used by other fucntions?
I was hoping for something about, say how to decompose a 10,000 line function with cross-cutting concerns into multiple files.
BTW, I felt unease with:
STOPWORDS = set(
map(str.lower,
map(str.strip,
open(os.path.join(FILE, 'stopwords'), 'r').readlines()
)
)
)
I feel better with:
STOPWORDS = set(line.strip().lower() for line in
open(os.path.join(FILE, 'stopwords'))
While there aren't enough stopwords that this will be a performance issue, according to my timings using /usr/share/dict/words on a Mac for 100 reads, it may have made performance sense for Python 2.7 to use this approach:
== Python 2.7 ==
map 20.7530391216
me 24.4680659771
ratio: 1.17901122017
but under Python 3.7 the more concise (and I argue more readable) way is faster:
== Python 3.7 ==
map 19.93948793411255
me 19.127523183822632
ratio: 0.9592785555490216