The following simple LINQ code
string[] words = { "hello", "wonderful", "linq", "beautiful", "world" };
// Get only short words
var shortWords =
from word in words
where word.Length <= 5
select word;
// Print each word out
shortWords.Dump();
can be translated into python using list comprehension as follows.
words = ["hello", "wonderful", "linq", "beautiful", "world"]
shortWords = [x for x in words if len(x) <=5]
print shortWords
- Is LINQ just another idea to implement list comprehension?
- What examples might be that LINQ can do but list comprehension can't do.