While trying to workout list comprehension , I got stuck with desired value repeated.
I have 2 lists: L1, L2. Result required is list of items from L2 if these items are smaller than/ equal to, at least one of the items in L1.
L1=[10,20,30,40,50]
L2=[3,11,51]
L3=[d2 for d2 in L2 for d1 in l1 if d2<=d1]
L3 is returned as [3, 3, 3, 3, 3, 11, 11, 11, 11]
Answer contains valid items, but are repeated. I know using set(), we can get rid of repetitions but may be I am using list-comprehension in a wrong way. Any clarification would be appreciated.
Loops to achieve the desired result would be:
L3=[]
for d2 in L2:
for d1 in L1:
if d2<=d1:
L3.append(d2)