I want to compare list I1 against I2 and append elements which are less than or equal to the specific element in I1. But I am running into an error. I show the desired output for clarity. Thanks in advance for the help.
I1= [1, 4, 5, 8]
I2 = [2, 3, 5, 6]
J = [i for i in I1 if i <= I2]
print(J)
The error is
in <listcomp>
J = [i for i in I1 if i <= I2]
TypeError: '<=' not supported between instances of 'int' and 'list'
The desired output is
Output=[[],[2,3],[2,3,5],[2,3,5,6]]