To filter objects in Python you can select attributes of a class using the dot notation. Suppose
arr is an array of ProjectFile objects. Now you filter for SomeCocoapod using.
filter(lambda p: p.repo == "SomeCocoapod", arr)
NB: This returns a filter object, which is a generator. To have a filtered list back you can wrap it in a list constructor.
As a very Pythonic alternative, you can use list comprehensions:
filtered_arr = [p for p in arr if p.repo == "SomeCocoapod"]
Python filter object example
Simple example code.
def __init__(self, id):
self.id = id
list_of_objects = 
for i in range(5):
for obj in list_of_objects:
res1 = filter(lambda emp: emp.id == 1, list_of_objects)
res2 = [p for p in list_of_objects if p.id == 1]
Do comment if you have any doubts or suggestions on this Pytohn filter topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.