Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer Date: Tue, 29 Mar 2016 18:05:47 +0200 Organization: None Lines: 42 Message-ID: References: <56f9cffb$0$1614$c3e8da3$5496439d@news.astraweb.com> <56FA565A.9020800@mail.de> <56FAA22E.3040805@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de Qqj3pZIWJu12x5HYtlUVEAdKotlvXlLcPF1UqH2x+WZg== 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; 'subject:: [': 0.03; 'subject:Python': 0.05; 'expressions': 0.07; 'variant': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'mylist': 0.16; 'optimised': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'still,': 0.16; 'subject:Learning': 0.16; 'subject:programmer': 0.16; 'wrote:': 0.16; 'subject:] ': 0.19; '>>>': 0.20; 'assuming': 0.22; 'progress.': 0.22; 'select': 0.23; 'bit': 0.23; "python's": 0.23; 'this:': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'skip:" 20': 0.26; 'equivalent': 0.27; 'question': 0.27; 'looks': 0.29; 'url:wikipedia': 0.29; 'url:wiki': 0.30; 'subject:) ': 0.32; '"")': 0.33; 'foo': 0.33; 'mine': 0.35; 'quite': 0.35; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'url:en': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'friend': 0.81; 'otten': 0.84; 'subject:you': 0.85 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9f8e.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105992 Sven R. Kunze wrote: > On 29.03.2016 12:18, Sven R. Kunze wrote: >> On 29.03.2016 11:39, Peter Otten wrote: >>> My question to those who know a bit of C#: what is the state-of-the-art >>> equivalent to >>> >>> "\n".join(foo.description() for foo in mylist >>> if foo.description() != "") >>> >> >> Using LINQ, I suppose: >> https://en.wikipedia.org/wiki/Language_Integrated_Query > > Friend of mine told me something like this: > > String.Join("\n", mylist.Where(foo => > !String.IsNullOrEmpty(foo.description)).Select(foo => foo.description)) > > [untested, but from what I know of quite correct] Reformatting it a bit String.Join( "\n", mylist.Where( foo => !String.IsNullOrEmpty(foo.description) ).Select( foo => foo.description)) this looks like a variant of Python's str.join( "\n", map(lambda foo: foo.description, filter(lambda foo: foo.description, mylist))) Assuming it's type-safe and can perhaps reshuffle the where and select part into something optimised there is definitely progress. But still, Python's generator expressions are cool..