Unpacking
1 | for index, item in enumerate(some_list): |
Create an ignored variable
if you need to assign something but will not need that variable, use__:1
2filename = 'foobar.txt'
basename, __, ext = filename.rpartition('.')
####Create a length-N list of the same thing1
2four_nones = [None] * 4
four_lists = [[] for __ in xrange(4)]
Short ways to manipulate lists
1 | # filter elements greater than 4 |
Line continuations
use parenthesis rather than backslash, an unexpected white space after the backslash will break the code.