#NEWLINE# def partition( pred , iterable ) : #NEWLINE# #INDENT# 'Divides elements of given iterable in two,\n    based on whether they satisfy given predicate.\n    :return: Tuple (elems_that_satisfy, elems_that_dont_satisfy).\n    ' #NEWLINE# pred = ( pred or bool ) #NEWLINE# true_elems = itertools . ifilter ( pred , iterable ) #NEWLINE# false_elems = itertools . ifilterfalse ( pred , iterable ) #NEWLINE# res = ( true_elems , false_elems ) #NEWLINE# for cls in ( str , unicode , tuple , list ) : #NEWLINE# #INDENT# if isinstance ( iterable , cls ) : #NEWLINE# #INDENT# res = map ( cls , res ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# return res