[Tutor] Ugly python one-liner !

Prahlad Vaidyanathan slime@vsnl.net
Mon, 8 Jul 2002 22:59:30 +0530


Hi,

    I was again playing around with the matrix module I have been
working on recently, and I found I could write this absolutely perl-ish
one-liner to compute the one-norm of the matrix.

"""
    def one_norm (self) :
        """The sum of the elements in different rows of each column
        is computed, and the maximum of these values is said to
        be the one-norm of the Matrix.
        """
        return max([reduce(lambda x,y: x+y, \
                    [abs(self[r,c]) for r in range(self.rows)]) \
                        for c in range(self.columns)])
"""

    Between map(), reduce() and list comprehension, I have finally
succeeded in making python look scary :-)

pv.
-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

Men will always be men -- no matter where they are.
		-- Harry Mudd, "Mudd's Women", stardate 1329.8