I have finished the basic codecademy exercise but I have forgotten almost everything I learnt so I am back. In the exercise below, I am trying to find the numbers common to both lists a and b. One can probably do this using the principles in Venn Diagram but I want to see if it can be done by list comprehension. In this instance my expression is x-y, (x minus y), because if you subtract two numbers of equal value the answer should be zero. In the code below, I am getting the error message
"There is an error (invalid syntax) at line 8" i.e., the last line. Please help. Two questions
- Is it possible to use the expression x - y?
- What is wrong with the last line?
The numbers generated are random. I have included some numbers so as to repeat them e.g 5 and 21. Thank you
<In what way does your code behave incorrectly? Include ALL error messages.>
<What do you expect to happen instead?>```python
a=[2, 5, 9, 10, 12, 13, 15, 18,5, 20, 21, 24, 25, 26, 28, 30]
b=[5, 7, 14, 15, 17, 21, 21,24, 25, 27, 28, 29, 30, 31]
[x-y for x in a and y in b if x -y == 0 c.append (x)]
<do not remove the three backticks above>