I have to sum up a subset of items in a list. The numbers I use to calculate the indices are given in another list. The indices may change, but the list I'm summing from does not. Both lists are of known size. This bit of code is in a nested loop in my program, and it's by far the slowest part.

I need a fast and clean way to do this in Python 3. 

An obvious solution I have tried is just hardcoding the sum of all the different items. I've also tried a much cleaner solution using `enumerate` and summing a comprehension. The problem is that the latter is much slower than the former.

The exact index to use is `2 * i + x` where `i` is the index in `indices` and `x` is the number in `indices`. (The indices list represents a set of choices between values concatenated into the lookup table.)

```py
# sample code - the real lists are much larger

lookup = [7, 10, 1, 4, 1, 7, 9, 3, 5, 6]
indices = [0, 1, 0, 0, 1]

# hardcoded solution
s = lookup[2 * 0 + indices[0]] + lookup[2 * 1 + indices[1]] + lookup[2 * 2 + indices[2]] + lookup[2 * 3 + indices[3]] + lookup[2 * 4 + indices[4]]

# Pythonic solution with enumerate
s = sum(lookup[2 * i + x] for i, x in enumerate(indices))

```

I have tested both of these options using [perf](https://perf.readthedocs.io/en/latest/). The clean solution with `enumerate` is just over 3 times slower than the hardcoded version. The rest of the code is fairly optimized, so my whole program is almost 3 times slower if I go with the clean version.

Is there something faster I could do? Answers that require preprocessing the `lookup` list in some way are okay: that list is only built once but used many times.

Edit: here is a complete example of a case where hardcoding lookups to a list seems to be much faster than any alternative. The following code runs in Pypy3 in 0.27s, and the commented out slow version runs in 2.8s. (Obviously there are faster ways to do this particular task.)

```
from itertools import product

lookup = [1, 7, 7, 1, 2, 9, 9, 9, 2, 2, 8, 8, 9, 6, 5, 10, 3, 4, 7, 10, 1, 3, 0, 1, 7, 1, 3, 4, 2, 9]
largest_sum = 0
largest_sum_indices = []

for indices in product(list(range(0,2)), repeat=15):
    # simulate checking many different lookup lists
    for _ in range(200):
        s = lookup[2 * 0 + indices[0]] + lookup[2 * 1 + indices[1]] + lookup[2 * 2 + indices[2]] + lookup[2 * 3 + indices[3]] + lookup[2 * 4 + indices[4]] + lookup[2 * 5 + indices[5]] + lookup[2 * 6 + indices[6]] + lookup[2 * 7 + indices[7]] + lookup[2 * 8 + indices[8]] + lookup[2 * 9 + indices[9]] + lookup[2 * 10 + indices[10]] + lookup[2 * 11 + indices[11]] + lookup[2 * 12 + indices[12]] + lookup[2 * 13 + indices[13]] + lookup[2 * 14 + indices[14]]
        # clean method is too slow
        #s = sum(lookup[i * 2 + x] for i,x in enumerate(indices))
        if s > largest_sum:
            largest_sum = s
            largest_sum_indices = indices

print(largest_sum)
print(largest_sum_indices)

```