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

Vito De Tullio vito.detullio at gmail.com
Tue Mar 29 17:36:05 EDT 2016


Sven R. Kunze 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() != "")

> Friend of mine told me something like this:
> 
> String.Join("\n", mylist.Where(foo =>
> !String.IsNullOrEmpty(foo.description)).Select(foo => foo.description))


I don't know if is "better" or not, but I find more readable using the 
"sql"-like syntax


string.Join("\n", from foo in mylist
                  where !string.IsNullOrEmpty(foo.description())
                  select foo.description());

which is relatively similar to the python's comprehension.


-- 
By ZeD




More information about the Python-list mailing list