2 ms·
The use of `enumerate` in some of the general examples doesn't seem right to me. Take, for instance, the part of the general solution: for r, _ in enumera
by WaffleIronMaker 4y ago
The use of `enumerate` in some of the general examples doesn't seem right to me.
Take, for instance, the part of the general solution:
for r, _ in enumerate(RESOURCES):
solver.Add(sum(DATA[u][r] * units[u] for u, _ in enumerate(units)) <= RESOURCES[r])
the author is basically using enumerate to get the indices from the list, and nothing else. It seems like it would be much better to either do:
for r, resource in enumerate(RESOURCES):
solver.Add(sum(DATA[u][r] * unit for u, unit in enumerate(units)) <= resource)
`enumerate` is supposed to return both the index and the value, so indexing the list you just passed to `enumerate` seems like bad form.
Is there some reason not to do it this way?
- Helmut10001 4y agoThis is the way.