[CentralOH] 2015-01-30 道場 Scribbles 落書/惡文? quoting, docstrings, heapq, sorted, spam, zen, memoize, recursion
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Sat Jan 31 21:05:20 CET 2015
lots of folks tonight
one newcomer to python had fun with refactoring
that simplified and clarified code
wp: prefix means Wikipedia
To get good answers, consider following the advice in the links below.
http://catb.org/~esr/faqs/smart-questions.html
http://web.archive.org/web/20090627155454/www.greenend.org.uk/rjk/2000/06/14/quoting.html
Although the regular expression is naïve,
what is the following command remarkably effective at identifying?
grep ' CentralOH mailing list'
http://nbviewer.ipython.org/url/colug.net/python/cohpy/20150126/cohpy-20150126-3-next-eyeballs.ipynb
If it seems awkward, it is awkward.
If it seems too complicated, it is too complicated.
"telephone test" for explaining code
premature optimization is the root of all evil
Write for clarity first.
PEP #8
PEP #20
pycharm
vim versus emacs
whocalled.me has an API
integrate with phone to identify undesirable callers before answering phone
heapq versus sorted()
Knuth versus McIlroy
http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/
wp:Unix philosophy
wp:Linear regression
quoting
'hello'
"hello"
'''hello''' may span multiple lines
"""hello""" may span multiple lines
docstrings
PEP 257 - Docstring Conventions
https://www.python.org/dev/peps/pep-0257/
wp:Repetitive strain injury
http://pianomap.com/injuries/index.html
wp:recursion
wp:Relativity (M. C. Escher)
wp:Gödel, Escher, Bach
wp:Bach: The Goldberg Variations (Glenn Gould recording)
wp:Glenn Gould
wp:Strange loop
wp:Fawlty Towers
wp:Basil Fawlty
wp:John Cleese
wp:Monty Python
wp:Python (programming language)
wp:Pythonesque (play)
http://www.python-course.eu/python3_memoization.php
wp:Memoization
https://duckduckgo.com/html/?q=python%20memoize%20generator%20yield
http://colug.net/python/dojo/20150131/
http://nbviewer.ipython.org/github/mrocklin/pydata-toolz/blob/master/7-fib-memoize.ipynb
1: with ordinary function stuff
def memoize(f):
results = {}
def helper(x):
if x not in results:
results[x] = f(x)
return results[x]
return helper
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
fib = memoize(fib)
print(fib(40))
2: using function decorator
def memoize(f):
results = {}
def helper(x):
if x not in results:
results[x] = f(x)
return results[x]
return helper
@memoize
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
#fib = memoize(fib)
print(fib(40))
Rickie Lee Jones - Pop Pop
More information about the CentralOH
mailing list