def sum_two_lists(self, llist): first = self.head second = llist.head carry = 0 sum_llist = LinkedList() while first or second: f = first.data if first is not None else 0 s = second.data if second is not None else 0 summ = f + s + carry carry = summ // 10 sum_llist.append(summ % 10) first = first.next if first is not None else None second = second.next if second is not None else None return sum_llist
Hello @Prasanth_Ganesan ,
Thank you for sharing this code. But the purpose of the course is to teach readers how data structures and algorithms work so the code was written in such a way that it’s easier to understand.
Hope this answers your query