Mensanator wrote:
On Jun 6, 1:40 pm, The Pythonista <[EMAIL PROTECTED]> wrote:
On Thu, 05 Jun 2008 23:42:07 -0400, John Salerno wrote:
Is it possible to write a list comprehension for this so as to produce a
list of two-item tuples?
base_scores = range(8, 19)
score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3] print zip(base_scores,
score_costs)
score_costs = [(base_scores[i], score_costs[i]) for i in range (len
(base_scores))]

What happens if your iterables aren't the same length?

But, I'd rather just use zip. :-)

And with zip() you won't get an error, but it won't be correct,
either.


Wouldn't it be nice to have leftZip(), rightZip(), and fullZip() for when the lists have different lengths? The final tuples for a leftZip could be in the form (value, ) and for right zip (, value) (though I think this last tuple is not allowed in python's syntax, we might define a "Null" or "Empty" name to act as a place holder in the resulting tuples).

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to