<s> from itertools import chain <EOL> from functools import wraps <EOL> from collections import defaultdict <EOL> from unstdlib . six import string_types <EOL> from unstdlib . six . moves import xrange <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def groupby_count ( i , key = None , force_keys = None ) : <EOL> """<STR_LIT>""" <EOL> counter = defaultdict ( lambda : <NUM_LIT:0> ) <EOL> if not key : <EOL> key = lambda o : o <EOL> for k in i : <EOL> counter [ key ( k ) ] += <NUM_LIT:1> <EOL> if force_keys : <EOL> for k in force_keys : <EOL> counter [ k ] += <NUM_LIT:0> <EOL> return counter . items ( ) <EOL> def is_iterable ( maybe_iter , unless = ( string_types , dict ) ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> iter ( maybe_iter ) <EOL> except TypeError : <EOL> return False <EOL> return not isinstance ( maybe_iter , unless ) <EOL> def iterate ( maybe_iter , unless = ( string_types , dict ) ) : <EOL> """<STR_LIT>""" <EOL> if is_iterable ( maybe_iter , unless = unless ) : <EOL> return maybe_iter <EOL> return [ maybe_iter ] <EOL> def iterate_items ( dictish ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( dictish , '<STR_LIT>' ) : <EOL> return dictish . iteritems ( ) <EOL> if hasattr ( dictish , '<STR_LIT>' ) : <EOL> return dictish . items ( ) <EOL> return dictish <EOL> def iterate_chunks ( i , size = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> accumulator = [ ] <EOL> for n , i in enumerate ( i ) : <EOL> accumulator . append ( i ) <EOL> if ( n + <NUM_LIT:1> ) % size == <NUM_LIT:0> : <EOL> yield accumulator <EOL> accumulator = [ ] <EOL> if accumulator : <EOL> yield accumulator <EOL> def iterate_flatten ( q ) : <EOL> """<STR_LIT>""" <EOL> return chain . from_iterable ( q ) <EOL> def listify ( fn = None , wrapper = list ) : <EOL> """<STR_LIT>""" <EOL> def listify_return ( fn ) : <EOL> @ wraps ( fn ) <EOL> def listify_helper ( * args , ** kw ) : <EOL> return wrapper ( fn ( * args , ** kw ) ) <EOL> return listify_helper <EOL> if fn is None : <EOL> return listify_return <EOL> return listify_return ( fn ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import doctest <EOL> doctest . testmod ( optionflags = doctest . ELLIPSIS ) </s>
