Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattjmorrison/863187 to your computer and use it in GitHub Desktop.
Save mattjmorrison/863187 to your computer and use it in GitHub Desktop.
def one_third(x):
return x / 3.0
def make_table(pairs):
'Unoptimized Example'
result = []
for value in pairs:
x = one_third(value)
result.append(format(value, '9.5f'))
return '\n'.join(result)
def make_table2(pairs):
'Optimized version'
result = []
result_append = result.append # bound method
_format = format # localized
for value in pairs:
x = value / 3.0 # in-lined
result_append(_format(value, '9.5f'))
return '\n'.join(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment