Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'element': 0.07; 'name?': 0.09; 'subject:language': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; '"def"': 0.16; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'shortcut': 0.16; 'subject: \n ': 0.16; 'tuple': 0.16; 'index': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'slot': 0.31; 'allows': 0.31; 'received:google.com': 0.35; 'pm,': 0.38; 'even': 0.60; 'more': 0.64; 'chance': 0.65; 'mar': 0.68; 'gain': 0.79; 'subject:this': 0.83; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=YDYsZxHzzopVQWtGhd+fW4yT7GBugbdtReVRJVxKTxs=; b=YW3qDQfW8EzeOBnnWNIos21t+V1qkLYRvLf0GdClr8tcdDJ00UECZYtZlLpLsznUte CQ/EQGFyhmUGer0JzPjKIFKdJwInnJmfIAJFKAfl27zmQDtZDO+74dxOTo+dOO4qdiak kQ0+u60Ez5nW+Jj3YTkiR3G2/M5WnWjntQvDEP+7HWpiHMbJ79+Loi04nhptxF8bHplm XBI1VGAm/SOt6LLxWjoHJeK3w9KDfBtZJEtg4Q6+PF0BOvO23EdHhDNce6lTvgClgjA7 U1dUxs5ozTlvFA91cR7sRD75Bgo8fE+/6ePNKWK8QjAGQ0Ka8YflPLl7qnbdMWs85aC1 YndA== MIME-Version: 1.0 X-Received: by 10.66.27.202 with SMTP id v10mr8634266pag.127.1395665592280; Mon, 24 Mar 2014 05:53:12 -0700 (PDT) In-Reply-To: <87r45rzsbj.fsf@elektro.pacujo.net> 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> Date: Mon, 24 Mar 2014 23:53:12 +1100 Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395665601 news.xs4all.nl 2945 [2001:888:2000:d::a6]:59681 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68876 On Mon, Mar 24, 2014 at 11:36 PM, Marko Rauhamaa wrote: >> def get_oneth_element_index(item): >> return item[1].index >> L.sort(key=get_oneth_element_index) >> >> 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. It's the index of element 1. What more do you need to know? Is it actually any help to give that a name? All you gain is a chance for the name, the purpose, and the functionality to come into disagreement. ChrisA