I'm trying to learn neat pythonic ways of doing things, and was wondering why my for loop cannot be refactored this way:
q = [1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5]
vm = [-1, -1, -1, -1]
for v in vm:
if v in q:
p.append(q.index(v))
else:
p.append(99999)
vm[p.index(max(p))] = i
I tried replacing the for loop with:
[p.append(q.index(v)) if v in q else p.append(99999) for v in vm]
But it doesn't work. The for v in vm:
loop evicts numbers from vm
based on when they come next in q
.