Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'plenty': 0.07; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:language': 0.09; 'def': 0.12; 'language.': 0.14; '"def"': 0.16; 'lambda': 0.16; 'once.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'shortcut': 0.16; 'similarly,': 0.16; 'subject: \n ': 0.16; 'tuple': 0.16; 'language': 0.16; 'wrote:': 0.18; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'own.': 0.24; 'skip:l 30': 0.24; '---': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'skip:g 30': 0.30; 'subject:list': 0.30; 'breaking': 0.31; 'slot': 0.31; 'allows': 0.31; 'week.': 0.33; 'cases': 0.33; 'there': 0.35; 'version': 0.36; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'free': 0.61; 'viruses': 0.61; "you're": 0.61; 'name': 0.63; 'protection': 0.63; 'our': 0.64; 'here': 0.66; 'antivirus': 0.68; 'day': 0.76; 'subject:this': 0.83; 'clearer': 0.84; 'received:2': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) Date: Mon, 24 Mar 2014 14:21:02 +0000 References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <87bnwv2a5v.fsf@elektro.pacujo.net> <87r45rzsbj.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-198-214.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: <87r45rzsbj.fsf@elektro.pacujo.net> X-Antivirus: avast! (VPS 140324-0, 24/03/2014), Outbound message X-Antivirus-Status: Clean 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395670865 news.xs4all.nl 2872 [2001:888:2000:d::a6]:52905 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68880 On 24/03/2014 12:36, Marko Rauhamaa wrote: > Chris Angelico : > >> Similarly, there are plenty of cases where a nameless function is MUCH >> clearer than breaking it out into a separate def and then using the >> name once. Do you name the function for what it does internally? >> >> def get_oneth_element_index(item): >> return item[1].index >> L.sort(key=get_oneth_element_index) >> >> Or for how you're using it? >> >> def keyfunc(item): >> return item[1].index >> L.sort(key=keyfunc) >> >> Or do you just shortcut the whole thing by inlining it? >> >> L.sort(key=lambda item:item[1].index) > > I still prefer the "def" variant. It even allows you to clarify the > meaning of the tuple slot by using a nicer name. > Each to their own. Here give me the lambda version any day of the week. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com