map, index

Paul Rubin no.email at nospam.invalid
Sun Mar 28 22:46:40 CEST 2010


Luis Quesada <l.quesada at 4c.ucc.ie> writes:
>> [ id*v for id,v in enumerate(L) ]
> Cool! Thanks!

If you really want to write that in pointfree style (untested):

   import itertools, operator
   ...
   itertools.starmap(operator.mul, enumerate(L))

For your other question, you could probably do something ugly
with ifilter, but it's not worth it.  

For the style of programming you're interested in, you should read the
docs for the itertools module.  Python culture in general tends to
not be that fond of heavy use of HOF's, since it's very easy to make
mistakes with its iterator protocol and with its dynamic type system.



More information about the Python-list mailing list