srcList = [[(23,)],[(124,)],[(45,)]]
dstList = []
#--------------------------------------------------------------------
def Expand( srcList ) :
if hasattr(srcList, '__iter__'):
for i in srcList:
Expand( i )
else:
dstList.append( srcList )
#--------------------------------------------------------------------
if __name__ == '__main__':
Expand( srcList )
print dstList
another similar approach likes the following code.
#--------------------------------------------------------------------
class Expander:
def __init__( self ):
self.resultList = []
def Expand( self, srcList ):
self.resultList = []
self.Internal_Expand( srcList )
return self.resultList
def Internal_Expand( self, srcList ):
if hasattr(srcList, '__iter__'):
for i in srcList:
self.Internal_Expand( i )
else:
self.resultList.append( srcList )
#--------------------------------------------------------------------
if __name__ == '__main__':
srcList = [[(23,)],[(124,)],[(45,)]]
print Expander().Expand( srcList )
#--------------------------------------------------------------------
ok, finally i find this way.
#--------------------------------------------------------------------
def Expand( srcList ):
resultList = []
def Internal_Expand( xList ):
if hasattr(xList, '__iter__'):
for i in xList:
Internal_Expand( i )
else:
resultList.append( xList )
Internal_Expand( srcList )
return resultList
#--------------------------------------------------------------------
if __name__ == '__main__':
srcList = [[(23,)],[(124,)],[(45,)]]
print Expand( srcList )
#--------------------------------------------------------------------