#NEWLINE# def previous_current_next( items ) : #NEWLINE# #INDENT# '\n    From http://www.wordaligned.org/articles/zippy-triples-served-with-python\n\n    Creates an iterator which returns (previous, current, next) triples,\n    with ``None`` filling in when there is no previous or next\n    available.\n    ' #NEWLINE# extend = itertools . chain ( [ None ] , items , [ None ] ) #NEWLINE# ( previous , current , next ) = itertools . tee ( current , 3 ) #NEWLINE# try : #NEWLINE# #INDENT# current . next ( ) #NEWLINE# next . next ( ) #NEWLINE# next . next ( ) #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return itertools . izip ( previous , current , next )