Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'lawrence': 0.09; 'measure': 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; "wouldn't": 0.14; 'fits': 0.16; 'item:': 0.16; 'itemgetter': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipe': 0.16; 'recipes': 0.16; 'subject: \n ': 0.16; 'written.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'versions': 0.24; '---': 0.24; 'sort': 0.25; "i've": 0.25; 'shown': 0.26; 'this:': 0.26; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'subject:list': 0.30; "i'm": 0.30; 'lines': 0.31; 'that.': 0.31; 'bunch': 0.31; "d'aprano": 0.31; 'steven': 0.31; "they'll": 0.31; 'probably': 0.32; 'skip:d 20': 0.34; 'done,': 0.36; 'version,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'free': 0.61; 'viruses': 0.61; 'first': 0.61; 'protection': 0.63; 'our': 0.64; 'love': 0.65; 'antivirus': 0.68; 'fact,': 0.69; 'subject:this': 0.83; 'beats': 0.84; 'contemplate': 0.84; 'received:2': 0.84; 'luck': 0.93 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: Tue, 25 Mar 2014 02:06:53 +0000 References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> <532fffaf$0$29878$c3e8da3$5496439d@news.astraweb.com> <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> 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: <5330df9e$0$29994$c3e8da3$5496439d@news.astraweb.com> X-Antivirus: avast! (VPS 140324-1, 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395713237 news.xs4all.nl 2849 [2001:888:2000:d::a6]:39276 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68932 On 25/03/2014 01:45, Steven D'Aprano wrote: > > (1) People who just want to get the job done, without learning a bunch of > theory, *won't care* how their sort key function is written. They're > looking for a recipe that they can copy and paste, and whether you write > it like this: > > data.sort(key=lambda item: item[1]) > > or like this: > > from operator import itemgetter > data.sort(key=itemgetter(1)) > > or like this: > > def sort_key(item): > return item[1] > data.sort(key=sort_key) > > > *they won't care*. In fact, they'll probably prefer the first version, > with lambda, because it is fewer lines to copy. > I'm firmly in this camp, practicality beats purity and all that. I've used the first and second versions shown above as they happened to be in the recipes I was aquiring, I wouldn't contemplate the third. That's just my mindset, which is what I love about Python, by pure luck it fits me like made to measure clothing. -- 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