﻿ Python: Find missing and additional values in two lists - w3resource

Python: Find missing and additional values in two lists

Python List: Exercise - 42 with Solution

Write a Python program to find missing and additional values in two lists.

Sample Solution:

Python Code :

``````# Define two lists 'list1' and 'list2' containing elements
list1 = ['a', 'b', 'c', 'd', 'e', 'f']
list2 = ['d', 'e', 'f', 'g', 'h']

# Calculate the missing values in 'list2' by finding the set difference between 'list1' and 'list2'
missing_values = set(list1).difference(list2)

# Print the missing values in the second list 'list2'
print('Missing values in the second list: ', ','.join(missing_values))

# Calculate the additional values in 'list2' by finding the set difference between 'list2' and 'list1'

# Print the additional values in the second list 'list2'
```
```

Sample Output:

```Missing values in second list:  b,c,a
Additional values in second list:  g,h
```

Flowchart:

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿