#NEWLINE# def __iter__( self ) : #NEWLINE# #INDENT# import itertools #NEWLINE# def roundrobin( * iterables ) : #NEWLINE# #INDENT# "roundrobin('ABC', 'D', 'EF') --> A D E B F C" #NEWLINE# pending = len ( iterables ) #NEWLINE# if PY3 : #NEWLINE# #INDENT# nexts = itertools . cycle ( ( iter ( it ) . __next__ for it in iterables ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# nexts = itertools . cycle ( ( iter ( it ) . next for it in iterables ) ) #NEWLINE# #UNINDENT# while pending : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# for next in nexts : #NEWLINE# #INDENT# ( yield next ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# pending -= 1 #NEWLINE# nexts = itertools . cycle ( itertools . islice ( nexts , pending ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if all ( ( set . is_iterable for set in self . args ) ) : #NEWLINE# #INDENT# return roundrobin ( * ( iter ( arg ) for arg in self . args ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( 'Not all constituent sets are iterable' )