list comprehension question
Terry Reedy
tjreedy at udel.edu
Wed Oct 17 01:21:36 EDT 2012
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
> I've been teaching myself list comprehension, and i've run across
> something i'm not able to convert.
list comprehensions specifically abbreviate the code that they are
(essentially) equivalent to.
res = []
for item in source:
res.append(f(item))
res
<==>
[f(item) for item in source]
Matrix multiplication does not fit the pattern above. The reduction is
number addition rather than list appending.
--
Terry Jan Reedy
More information about the Python-list
mailing list