Skip to content

Instantly share code, notes, and snippets.

@Nimster
Created April 8, 2012 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimster/2334466 to your computer and use it in GitHub Desktop.
Save Nimster/2334466 to your computer and use it in GitHub Desktop.
Quick reference to some common python idioms/capabilities - mainly to serve as a reminder for me
collections.defaultdict(lambda: 0) # Hash map with default values
l = [t for t in l if not t in s] # Given a list l and a set s, returns l without all the elements in s
fun_with_many_args(*[1, 2, 3]) # Splat an array into an argument list
fun_with_named_args(**{'arg1': 1, 'arg2': 2}) # Splat a map (dictionary) for named argument functions!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment