Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python中类似于c#LINQ的Foreach循环where子句_Python 2.7 - Fatal编程技术网

Python 2.7 Python中类似于c#LINQ的Foreach循环where子句

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循环。其他我都记下来了 谁能给

我试图在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循环。其他我都记下来了


谁能给我指出正确的方向吗?

是的,很简单。带方括号的东西叫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