以下简单的LINQ代码
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();
Run Code Online (Sandbox Code Playgroud)
可以使用列表推导将其翻译成python,如下所示.
words = ["hello", "wonderful", "linq", "beautiful", "world"]
shortWords = [x for x in words if len(x) <=5]
print shortWords
Run Code Online (Sandbox Code Playgroud)