there is a more elegant way to generate search indexes
I don’t think there is a more elegant way. Your code is very simple and straightforward.
perhaps without defining a special function?
Yes, it is definitely possible.
>>> [b for a in ((x,-x) for x in range(1, 10 + 1)) for b in a]
[1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]
source
share