Searching Array of Data Objects

I have a data object defined:

@dataclass
class Blower:
    id_: str
    name: str
    off: bool

As I create objects I place then into an array:

blwr=Blower(<blah blah>)
blowers.append(blwr)

Now I want to search ‘blowers’ for an object with a certain ‘id_’ value. I can’t seem to find how to do that. I’m guessing I need to use some kind of array search, other than rolling my own, but I don’t find one that fits this particular situation. Can someone help? TIA.

[Gw1500se1]
“Now I want to search ‘blowers’ for an object with a certain ‘id_’
value. I can’t seem to find how to do that.”

There is no built-in “array search” method to do this. Just roll your
own.

for index, blwr in enumerate(blowers):
    if blwr.id_ == value:
        print(index)
        break

Thanks. I kind of expected that.

You might consider placing the objects in a dict as (id, obj) pairs:

blowers = {
    1: Blower(1, "a", False),
    2: Blower(2, "b", False),
    3: Blower(3, "c", False),
    ...
}

Then you access them easily:

if id_value in blowers:
    ...

and you can still get a list, array, etc. from the dict values:

list(blowers.values())