# File: ChapterRecursion/listRec.py #If L is true - non empty - print the first element then process the rest of the list. # if the List is contains other lists within it. """ 123 1234 """ def printList(L): if L: # list is not empty print(L[0],end='') printList(L[1:]) # use 'slicing def printListC(L): if not L: return # if L empty do nothing if type(L[0]) == type([]): # if it is a list call printListC(First element) printListC(L[0]) else: # no list then just print print(L[0],end='') printListC(L[1:]) # continue ie process the rest of L def main(): printList([1,2,3]) print() printListC([[1,2],[[3],4]]) main()