Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105992

Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer

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 2016-03-29 18:05 +0200
Organization None
Message-ID <mailman.159.1459267581.28225.python-list@python.org> (permalink)
References <56f9cffb$0$1614$c3e8da3$5496439d@news.astraweb.com> <nddigv$74u$1@ger.gmane.org> <56FA565A.9020800@mail.de> <56FAA22E.3040805@mail.de>

Show all headers | View raw


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..

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Learning Python (or Haskell) makes you a worse programmer Steven D'Aprano <steve@pearwood.info> - 2016-03-29 11:44 +1100
  Re: Learning Python (or Haskell) makes you a worse programmer Ethan Furman <ethan@stoneleaf.us> - 2016-03-28 21:05 -0700
  Re: Learning Python (or Haskell) makes you a worse programmer Michael Torrie <torriem@gmail.com> - 2016-03-28 22:13 -0600
  [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer Peter Otten <__peter__@web.de> - 2016-03-29 11:39 +0200
  Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-29 12:05 +0200
  Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-29 12:18 +0200
  Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-29 17:41 +0200
  Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer Peter Otten <__peter__@web.de> - 2016-03-29 18:05 +0200
  Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-29 18:11 +0200
  Re: [OT] C# -- sharp or carp? was Re: Learning Python (or Haskell) makes you a worse programmer Vito De Tullio <vito.detullio@gmail.com> - 2016-03-29 23:36 +0200
  Re: Learning Python (or Haskell) makes you a worse programmer "Eric S. Johansson" <esj@harvee.org> - 2016-03-29 19:29 -0400
  Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-30 12:07 +0200
    Re: Learning Python (or Haskell) makes you a worse programmer BartC <bc@freeuk.com> - 2016-03-30 11:21 +0100
      Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-30 13:43 +0200
      Re: Learning Python (or Haskell) makes you a worse programmer "Eric S. Johansson" <esj@harvee.org> - 2016-03-30 09:06 -0400
      Re: Learning Python (or Haskell) makes you a worse programmer Chris Angelico <rosuav@gmail.com> - 2016-03-31 00:09 +1100
      Re: Learning Python (or Haskell) makes you a worse programmer "Eric S. Johansson" <esj@harvee.org> - 2016-03-30 09:37 -0400
  Re: Learning Python (or Haskell) makes you a worse programmer Tim Golden <mail@timgolden.me.uk> - 2016-03-30 11:14 +0100
    Re: Learning Python (or Haskell) makes you a worse programmer Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-31 10:36 +1300
      Re: Learning Python (or Haskell) makes you a worse programmer Travis Griggs <travisgriggs@gmail.com> - 2016-03-31 09:30 -0700
      Re: Learning Python (or Haskell) makes you a worse programmer Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-31 10:34 -0600
      Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-31 18:44 +0200
  Re: Learning Python (or Haskell) makes you a worse programmer "Sven R. Kunze" <srkunze@mail.de> - 2016-03-30 12:23 +0200

csiph-web