Python: Get the difference between two given lists, after applying the provided function to each list element of both
Difference of Lists with Function
Write a Python program to get the difference between two given lists, after applying the provided function to each list element of both.
- Create a set, using map() to apply fn to each element in b.
- Use a list comprehension in combination with fn on a to only keep values not contained in the previously created set, _b.
Sample Solution:
Python Code:
Sample Output:
[1.2] [{'x': 2}]
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to compute the symmetric difference between two lists after applying a transformation function to each element.
- Write a Python program to get the difference between two lists using a lambda function that rounds each element to one decimal place.
- Write a Python program to calculate the difference between two lists where each element is processed by a custom function extracting a specific attribute.
- Write a Python program to determine the difference between two lists after converting all string elements to lowercase using a provided function.
Go to:
Previous: Write a Python program to randomize the order of the values of an list, returning a new list.
Next: Write a Python program to create a list with the non-unique values filtered out.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.