Isn't score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3]
considered a literal?
Yep, but it's not the sole controller of the length of a list. There
are other things that might control the length of the list like del,
append, etc.
I believe I just said that. Perhaps I should have said
at the instant it's created, the length is determined
by the literal.
Remember,
score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3]
is preceeded by range(11), so of course AT THAT INSTANT,
the lengths match. But, as you say, there's no guarantee
that the list lengths will remain unchanged.
And that's why I'm saying it isn't necessarily a good idea
to assume that. For the way it's used, the zip function
IS assuming that.
What I meant is in some cases (not all) the list might semantically be
nonsense if it is of different length (i.e. it have fixed length).
Sure, but remember, the OP was asking how to do this in a
list comprehension where he doesn't have the option of
iterating through both lists like he does with zip.
When I mentioned that could be solved by enumerate, I said
it simultaneously guaratees that the index numbers automatically
end up the same length as the target list and avoids the
hypothetical case where the list lengths somehow don't match.
Of course nothing can be done if the actual list length is
semantically nonsense and you actually might need to exploit
the truncating of the list to a fixed range. But there are
many cases where you DON'T want that to happen (if you deposit
5 checks at the bank, you certainly want credit for ALL of them,
not just some idiot's notion that only 4 can be deposited in
a single transaction.)
I think it is up to the programmer to decide whether special case is
enough or a general case is necessary.
Yes, he can certainly decide. Provided he knows what all the
options are. There's no way to tell if the OP understands
what the options are. I say it's always better to supply too
much information than not enough. Assume the reader is clever
enough to seperate the wheat from the chaff. If it turns out
he's not, then I at least _I_ will be blameless.