Learn Programming and technology with ease @ developerpublish.com

# Python Program to Add Corresponding Positioned Elements of Two Linked Lists

## Problem Statement

Given two linked lists with the same length, your goal is to create a new linked list where each nodeâ€™s value is the sum of the values at the corresponding positions in the input linked lists.

## Python Program to Add Corresponding Positioned Elements of Two Linked Lists

```class Node:
def __init__(self, data):
self.data = data
self.next = None

def __init__(self):

def append(self, data):
new_node = Node(data)
else:
while current.next:
current = current.next
current.next = new_node

def display(self):
while current:
print(current.data, end=" -> ")
current = current.next
print("None")

while current1 and current2:
total = current1.data + current2.data
result.append(total)
current1 = current1.next
current2 = current2.next

return result

# Input: Creating two linked lists
elements1 = [1, 2, 3, 4]
for element in elements1:

elements2 = [5, 6, 7, 8]
for element in elements2:

result_list.display()
```

## Input / Output

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...