I am trying to solve the problem how to transfer these two for loops into one list comprehension. We have these two lists and I would like to sort the first list according to the second list. With for loops it looks like this:
numbers = [-2, -8, 1, 17]
nov = [1, 2, 8, 17]
pon = []
for i in nov:
for x in numbers:
if abs(x) == i:
pon.append(x)
print(pon)
->>>[1, -2, -8, 17]
Is it somehow possible write these two loops as list comprehension? Thank you very much in advance.