Why you are wrong: you get the result, then filter it.
[(i,j) for i,j in enumerate(range(10))] will get [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)] , then you use if (3 < j) and (j < 8) (j - second element in the tuple), so the result will be [(4, 4), (5, 5), (6, 6), (7, 7)]
What you need to do: first filter the sequence passed to range() .
this means: for example, you want to list numbers from 4 to 7, so filter first
>>> [j for j in range(10) if 3 < j < 8] [4, 5, 6, 7]
then you pass it to enumerate :
>>> list(enumerate([4, 5, 6, 7])) [(0, 4), (1, 5), (2, 6), (3, 7)]
therefore the solution should be:
>>> list(enumerate(i for in range(10) if 3 < i < 8)) [(0, 4), (1, 5), (2, 6), (3, 7)]
In a word, just remember to do the first filtering .