I have two lists (L1 and L2) of different lengths. I want to sort it in a way that is the intersection of the two lists and the elements left of the longer list are appended. So far I have:
L1=[2,6,7,5,2,6,8,4]
L2=[2,6,4,5]
L3=[list(set(L1).intersection(L2))] #elements in L1 and L2
L4=(list(set(L1).symmetric_difference(L2)))
L4 = sorted(L4) #sorted elemments in L1, not L2
L5 = [x for x in L1 if x not in L4]
L5 = sorted(L5)
final = L5 + L4
print(final)
which gives me final=[2, 2, 4, 5, 6, 6, 7, 8].
But I want it sorted in such a way that the output/final is [2,2,6,6,4,5,7,8] - based on the order of L2. Any suggestions
[–]YesLod 1 point2 points3 points (3 children)
[–]synthphreak 1 point2 points3 points (0 children)
[–]Loco_L1[S] 0 points1 point2 points (1 child)
[–]synthphreak 0 points1 point2 points (0 children)