Find the Difference Between Two Lists in Python

  • Post category:List

Finding the difference between two lists in Python can be done using list comprehension or the set() function. Here are two examples:

Example 1:

Python

Output:

The difference between list1 and list2 is: [1, 2]

Example 2:

Python

Output:

The difference between fruits1 and fruits2 is: [‘banana’, ‘apple’]