# ChapterLists/flatten.py """ [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [1, 2, 3, 4, 5, 6, 7, 8, 9] 123456789 """ def myc(L): #recursive print if ( L == [] ): return [] else: print(L[0]) myc(L[1:]) def myrev(L): #recursive print if ( L == [] ): return [] else: return (myc(L[1:]) + [L[0]]) def main(): # flatten a list using a listcomp with two 'for' L = [ [1,2,3], [4,5,6], [7,8,9] ] R = [n for row in L for n in row] #[1, 2, 3, 4, 5, 6, 7, 8, 9] print(L,R) for r in L: #print(r) #[1,2,3] .. for j in r: print(j,end="") print('bye') main()