一千萬個為什麽

搜索

Python相當於C#LINQ的選擇


I'm quite new to python, and happen to have used C# for some time now. I saw that there was a filter method to use with the collections, which seems to be the equivalent of the LINQ's where clause.
I wondered, is there also an equivalent for the LINQ's select statement in python?
Example: my_collection.select(my_object => my_object.my_property) would return a collection of the my_property of each object in my_collection.

最佳答案

[my_object.my_property for my_object in my_collection]

轉載註明原文: Python相當於C#LINQ的選擇