Python 2.7 Python中类似于c#LINQ的Foreach循环where子句
我试图在python中复制一个c#LINQ foreach语句。我相信有更好的办法 假设我有(在c中):Python 2.7 Python中类似于c#LINQ的Foreach循环where子句,python-2.7,Python 2.7,我试图在python中复制一个c#LINQ foreach语句。我相信有更好的办法 假设我有(在c中): 公共类TestData { 公共int Id{get;set;} 公共字符串Something{get;set;} } void MyMethod() { List myList=新列表(); foreach(myList.Where中的变量i(x=>x.Id>5)) { //做点什么 } } 我想在python(2.7)中做类似的事情。我只需要foreach循环。其他我都记下来了 谁能给
公共类TestData
{
公共int Id{get;set;}
公共字符串Something{get;set;}
}
void MyMethod()
{
List myList=新列表();
foreach(myList.Where中的变量i(x=>x.Id>5))
{
//做点什么
}
}
我想在python(2.7)中做类似的事情。我只需要foreach循环。其他我都记下来了
谁能给我指出正确的方向吗?是的,很简单。带方括号的东西叫a
是的,很简单。带方括号的东西叫a
public class TestData
{
public int Id { get; set; }
public string Something { get; set; }
}
void MyMethod()
{
List<TestData> myList = new List<TestData>();
foreach (var i in myList.Where(x => x.Id > 5))
{
//do something
}
}
for i in [x for x in myList if x.Id > 5]:
pass #do something