We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Nice use of pop() here - good example of such a fundamental list method. My solution was the same up to that point, my first version had a "for item in items: print item".
Thanks, you're my lesson of the day! My Python code below with my version blanked via comment, yours is generally tighter than mine but the principle is the same:
defReversePrint(head):ifheadisNone:returnheadelse:items=[]currentNode=headwhilecurrentNodeisnotNone:items.append(currentNode.data)currentNode=currentNode.nextwhileitems:print(items.pop())"""else: items.reverse() for item in items: print(item)"""
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
Nice use of pop() here - good example of such a fundamental list method. My solution was the same up to that point, my first version had a "for item in items: print item".
Thanks, you're my lesson of the day! My Python code below with my version blanked via comment, yours is generally tighter than mine but the principle is the same: