Do this as a list comprehension?

John Salerno johnjsal at
Fri Jun 6 05:42:07 CEST 2008

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)

I can't think of how the structure of the list comprehension would work 
in this case, because it seems to require iteration over two separate 
sequences to produce each item in the tuple.

zip seems to work fine anyway, but my immediate instinct was to try a 
list comprehension (until I couldn't figure out how!). And I wasn't sure 
if list comps were capable of doing everything a zip could do.


More information about the Python-list mailing list