Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31466

Re: list comprehension question

From Terry Reedy <tjreedy@udel.edu>
Subject Re: list comprehension question
Date 2012-10-17 01:21 -0400
References <CA+C4C6f=24oD4seHY_-h1F0GMvBTWNYbzTABXOdtKkAZtE9hdQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2321.1350451320.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: list comprehension question Terry Reedy <tjreedy@udel.edu> - 2012-10-17 01:21 -0400
  Re: list comprehension question rusi <rustompmody@gmail.com> - 2012-10-17 00:13 -0700
    Re: list comprehension question Hans Mulder <hansmu@xs4all.nl> - 2012-10-17 10:34 +0200
    Re: list comprehension question Terry Reedy <tjreedy@udel.edu> - 2012-10-17 17:46 -0400

csiph-web