a break for comprehensions

Alex Martelli aleax at aleax.it
Thu Aug 9 05:35:31 EDT 2001


"Cliff Crawford" <cjc26 at nospam.cornell.edu> wrote in message
news:L_nc7.241033$EF2.29456854 at typhoon.nyroc.rr.com...
> * Cliff Crawford <cjc26 at nospam.cornell.edu> menulis:
> |
> | Then you can do stuff like the following, which simulates the Unix 'cat'
> | command (warning: untested):
> |
> | files = reduce(lambda x, y: x+y, GenList(iter(open(sys.argv[1:]))))
>
> Ooops, that should be
>
> files = reduce(lambda x, y: x+y,
>           [GenList(iter(open(filename))) for filename in sys.argv[1:]])

I think it should be
    files = reduce(operator.add,
        # whatever
after an import operator somewhere, of course.  I strongly
suggest NOT using lambda to duplicate the functions already
supplied by module operator -- it's slow and messy!-)


Alex






More information about the Python-list mailing list