You can use the Enumerable. Where extension method: var matches = myList. Where(p => p.Name == nameToExtract);
We can use hasattr() function to find if a python object obj has a certain attribute or property. hasattr(obj, 'attribute'): The convention in python is that, if the property is likely to be there, simply call it and catch it with a try/except block.
To check if the item exists in the list, use Python “in operator”. For example, we can use the “in” operator with the if condition, and if the item exists in the list, then the condition returns True, and if not, then it returns False.
As you can easily see from the documentation, the any()
function short-circuits an returns True
as soon as a match has been found.
any(x.name == "t2" for x in l)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With