Post

Answer: [8, 12]
Explanation:
This is a list comprehension:
c = [x for x in a if x not in b]
It means:
“Take each element x from list a and include it in c only if it is not present in list b.”
Now check each value from a:
5 → present in b, so exclude it
8 → not in b, so include it
12 → not in b, so include it
2 → present in b, so exclude it
English

@PythonPr c is a list comprehension that finds all values in list a that are not in list b. Final output is [8, 12]
English

@PythonPr 8 and 12 it evaluates completed expression first for each item in a if this item is not in b then print the item.
So goes on to check 5 in b yes present so it won't be printed
Similarly whatever item are present in b which are in a those will be not printed so 8,12
English

@PythonPr Easy one! The answer is [8, 12]. Always love a good Python quiz to start the day.
English

@PythonPr >>> a=[5,8,12,2]
>>> b=[18,2,46,5]
>>> c=[x for x in a if x in b]
>>> print(c)
[5, 2]
>>> c=[x for x in a if x not in b]
>>> print(c)
[8, 12]
English

@PythonPr Answer [8, 12]
The codeuses a list comprehension to filter elements.
Here's the logic;
Initialization:
List a contains [5, 8, 12, 2].
List b contains [18, 2, 46, 5].
The Filter: The line c = [x for x in a if x not in b] iterates through every number in list a and checks if it
English
























