Skip to content

Instantly share code, notes, and snippets.

@ansrivas
Last active October 7, 2017 23:20
Show Gist options
  • Select an option

  • Save ansrivas/b4bfa4a37b24f11ab4bd8e616b12ef3a to your computer and use it in GitHub Desktop.

Select an option

Save ansrivas/b4bfa4a37b24f11ab4bd8e616b12ef3a to your computer and use it in GitHub Desktop.
Python tips and tricks
  1. Concatenating a series of lists has quadratic performance. Use itertools.chain() or chain.from_iterable() instead.
  2. With #python iterators, we think of next() as initiating execution. With coroutines, we "await" a downstream event to initiate execution.
  3. Adding %(filename)s and %(lineno)d to the logging format makes it easier to see where log messages came from.
  4. The matrix multiplication operator "@" has the same precedence as multiplication, division, floor division, and remainder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment