I am using a recursive function to create a flow path through a maze. The function returns the correct path tuples (row,col), but I need it in the form of a List of tuples. For example I need to create this form
[(0,0),(1,1),(2,2),(3,3),(4,3)]
However the function returns this:
[(0, 0), [(1, 1), [(2, 2), [(3, 3), (4, 3)]]]]
Here is the function:
def FlowPathAt(fdir,row,col):
lItem = FlowOut(fdir,row,col)
if not lItem:
return (row,col)
else:
r,c = lItem
return [(row,col) , FlowPathAt(fdir,r,c)]
FlowOut(fdir,row,col)
is a function that returns the next cell address starting at (row,col)
Is there any way to flatten this list during the build?
Similar: How to flatten a list of tuples into a pythonic list