Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'function,': 0.07; 'raises': 0.07; 'python': 0.09; '(the': 0.15; '24,': 0.16; '33,': 0.16; '42,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operators.': 0.16; 'subject:which': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'module': 0.19; 'versions': 0.20; 'specifically': 0.24; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'question': 0.27; 'mind.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'smart': 0.29; 'generally': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'needed': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'functional': 0.36; 'thank': 0.36; 'received:209': 0.37; 'skip:l 20': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'most': 0.61; 'you.': 0.61; 'unnecessary': 0.65; '2013': 0.84; 'subject:better': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=w4OcR0+dtGbJ6xPQDN4GB4O+t6PspWMxuwPfnPGbL2Y=; b=ZM9woWkKwfTd/TYiJun+gmi9rcCKXkuuMK69EP2t8HOxHqhp6d+UB0cZVLim0+pQYj ErOywnd3w/HuLDDJIpTzD6B5MfZCb4Fl3Uh938CozJR7uKwL2UKbPCwlzF5dP8a4jeFH 9tDxBwVOwM0zT9jQRHef5yJ1oVqPJysOdOprWJ/XMwFe4xg289Qp+YDwlv59KUS4DPka wk51K/LgWC88z9HoHyMVWJkKTJMxM58m5cAG9tfZaqk+ZrjkfPX53TQwCpL0ZP2Kixjy 22ojFwjNbf9Oc9CjKNs6FF9wpnlsIFs27dtvdvsurxdhF+BxJFDLkrQiYRbA+6ebGPCq E4+Q== MIME-Version: 1.0 X-Received: by 10.52.67.164 with SMTP id o4mr16906406vdt.42.1363615383539; Mon, 18 Mar 2013 07:03:03 -0700 (PDT) In-Reply-To: References: Date: Tue, 19 Mar 2013 01:03:03 +1100 Subject: Re: "eval vs operator.methodcaller" - which is better? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363615385 news.xs4all.nl 6961 [2001:888:2000:d::a6]:45818 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41418 On Tue, Mar 19, 2013 at 12:58 AM, Laxmikant Chitare 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