Do this as a list comprehension?

Paul Hankin paul.hankin at gmail.com
Sun Jun 8 03:50:18 CEST 2008


On Jun 7, 7:21 pm, Paul Miller <n... at this.time> wrote:
> On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote:
> > What happens if your iterables aren't the same length?
>
> I chose not to consider that case, since they were the same length in the
> original post.  Based on the variable names, it seemed reasonable that
> there would always be a 1-to-1 correspondence between elements of each
> list.

If you think something is true but want to guarantee it, use assert.
Then when your assumption is wrong at least you find out.

assert len(base_scores) == len(score_costs)
score_costs = zip(base_scores, score_costs)

--
Paul Hankin



More information about the Python-list mailing list