Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41418
| References | <CAFtnWG-8dndo6KYrmKvgsbiB5YkfBOgbPLrzHXauuOygvGbHtw@mail.gmail.com> <CAPTjJmpDpqKfwx056VmR8umpX5aUPZsxNTVzGmXUkW_P_-ttYQ@mail.gmail.com> <CAFtnWG99JCUEvfhMFTMo5=bSbRw3Y80yqZH-as0RRCUUcSGiJQ@mail.gmail.com> |
|---|---|
| Date | 2013-03-19 01:03 +1100 |
| Subject | Re: "eval vs operator.methodcaller" - which is better? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3448.1363615385.2939.python-list@python.org> (permalink) |
On Tue, Mar 19, 2013 at 12:58 AM, Laxmikant Chitare <laxmikant.general@gmail.com> wrote: > Aha, that was smart Chris. Thank you. > > But this raises another question in my mind. What is the use case for > operator.methodcaller ? Most of the operator module is functional versions of what can be done elsewhere with operators. They're not generally needed unless you specifically need a function, such as for a map() call: >>> a=[1,2,3,4,5] >>> b=[50,40,30,20,10] >>> list(map(operator.add,a,b)) [51, 42, 33, 24, 15] (The list() call is unnecessary in Python 2, but means this will also work in Python 3.) ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "eval vs operator.methodcaller" - which is better? Chris Angelico <rosuav@gmail.com> - 2013-03-19 01:03 +1100
csiph-web