Three Minor Feature Requests for 2.2

Raymond Hettinger othello at javanet.com
Tue May 8 22:50:53 CEST 2001


1. Add an optional argument to reduce() to control whether the results are
accumulated left to right or right to left.

    def horner( coeffs, x ):
            'horner([6,3,4], 5) evaluates 6*x**2 + 3*x + 4 at x=5'
            return reduce( lambda sum,coeff,x=x:  cum*x+coeff, coeffs, 0.0,
REVERSE=1 )


2.  Amend the syntax for class definitions to optionally accept an empty
argument
list for superclasses.  This comes up when adding and then later removing
mix-ins.

    class C():              # should work as well as class C:


3.  Alter extend() to accept multiple sequence arguments:

    a = [1,2,3]
    a.extend( [4,5,6], [7,8,9] )

    def flatten( listoflists ):
        ans = []
        ans.extend( *listoflists )
        return ans


Raymond Hettinger  <-- too proud to re-request that eval() accept general
mapping arguments.





More information about the Python-list mailing list